Update: Ariakit Styles is in alpha. If you want to try it, join us on Discord (see the #news
channel).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
queryByLabelText, | |
queryByRole, | |
queryByText, | |
} from "@testing-library/dom"; | |
import type { ByRoleOptions, Matcher } from "@testing-library/dom"; | |
const roles = [ | |
"alert", | |
"alertdialog", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// notifications.tsx | |
import * as Ariakit from "@ariakit/react"; | |
interface Item extends Ariakit.NotificationStoreItem { | |
onUndo?: () => void; | |
} | |
export function useNotification() { | |
const notification = Ariakit.useNotificationContext(); | |
if (!notification) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef, useState } from "react"; | |
export function usePerceptibleValue<T>( | |
value: T, | |
{ delay = 0, minDuration = 350 } = {} | |
) { | |
const [perceptibleValue, setPerceptibleValue] = useState(value); | |
const nextThresholdRef = useRef(0); | |
useEffect(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ForwardedRef, useCallback } from 'react'; | |
type OptionalRef<T> = ForwardedRef<T> | undefined; | |
type Cleanup = (() => void) | undefined | void; | |
function setRef<T>(ref: OptionalRef<T>, value: T): Cleanup { | |
if (typeof ref === 'function') { | |
const cleanup = ref(value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AnyFunction = (...args: any[]) => any | |
function useEvent<T extends AnyFunction>(callback?: T) { | |
const ref = useRef<AnyFunction | undefined>(() => { | |
throw new Error("Cannot call an event handler while rendering.") | |
}) | |
// Or useInsertionEffect if it's React 18 | |
useLayoutEffect(() => { | |
ref.current = callback | |
}) |
Ariakit is the successor of Reakit, an open source library that provides lower-level React components and hooks for building accessible web apps, design systems, and other component libraries.
Reakit stands for React Toolkit. Ariakit stands for Aria Toolkit, which is better aligned with our goals.
Over the past years, we've been focusing more and more on the ARIA aspects of the library. In the future, we'd like to provide more framework-agnostic utilities.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LinkProps = AnchorHTMLAttributes<HTMLAnchorElement>; | |
const Link = createBlock<LinkProps>((props) => { | |
const { onSelectionChange, selectBlockContents } = useEditorState(props); | |
const popover = usePopoverState({ portal: true }); | |
const [href, setHref] = useState(props.href); | |
useEffect(() => { | |
setHref(props.href); | |
}, [props.href]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Calendar, | |
CalendarRow, | |
CalendarCell, | |
CalendarWeeks, | |
CalendarWeekDays, | |
} from "@ariakit/react"; | |
function MyCalendar() { | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
useTreeState, | |
Tree, | |
TreeItem, | |
TreeGroup, | |
TreeGroupLabel, | |
} from "ariakit/tree"; | |
function TreeView() { | |
const state = useTreeState({ defaultExpandedIds: ["item-1"] }); |
NewerOlder