- Spec files
npm-react-aria
Describes: pkg:npm/react-aria@3.43.x
- Description
- Comprehensive library of unstyled React hooks providing accessible UI primitives with full WAI-ARIA compliance and internationalization support.
- Author
- tessl
- Last updated
index.md docs/
1# React Aria23React Aria is a comprehensive library of unstyled React hooks that provides accessible UI primitives for building design systems and component libraries. It implements accessibility and behavior according to WAI-ARIA Authoring Practices, offering full screen reader and keyboard navigation support tested across multiple browsers, devices, and platforms.45## Package Information67- **Package Name**: react-aria8- **Package Type**: npm9- **Language**: TypeScript10- **Installation**: `npm install react-aria`1112## Core Imports1314```typescript15import { useButton, useTextField, useCheckbox } from "react-aria";16```1718For CommonJS:1920```javascript21const { useButton, useTextField, useCheckbox } = require("react-aria");22```2324## Basic Usage2526```typescript27import React from "react";28import { useButton } from "react-aria";2930function MyButton(props) {31let ref = React.useRef();32let { buttonProps } = useButton(props, ref);3334return (35<button {...buttonProps} ref={ref}>36{props.children}37</button>38);39}4041// Usage42<MyButton onPress={() => alert('Button pressed!')}>43Click me44</MyButton>45```4647## Architecture4849React Aria is built around several key design principles:5051- **Unstyled Components**: Provides behavior and accessibility without any visual styling52- **Hook-Based API**: Uses React hooks following `use*` naming convention for all functionality53- **WAI-ARIA Compliance**: Implements ARIA authoring practices for full accessibility support54- **Platform Adaptive**: Handles mouse, touch, keyboard, and screen reader interactions appropriately55- **Type Safety**: Full TypeScript support with comprehensive type definitions56- **Internationalization**: Built-in support for 30+ languages with RTL layout and localized formatting57- **Meta-Package Structure**: Aggregates focused hooks from individual @react-aria/* packages5859## Capabilities6061### Form Controls6263Interactive form elements with full accessibility support including labels, validation, keyboard navigation, color inputs, progress indicators, and sliders.6465```typescript { .api }66function useButton(props: AriaButtonProps, ref: RefObject<Element>): ButtonAria;67function useToggleButton(props: AriaToggleButtonProps, ref: RefObject<Element>): ButtonAria;68function useToggleButtonGroup(props: AriaToggleButtonGroupProps, ref: RefObject<Element>): ToggleButtonGroupAria;69function useToggleButtonGroupItem(props: AriaToggleButtonGroupItemProps, state: ToggleButtonGroupState, ref: RefObject<Element>): ButtonAria;70function useTextField(props: AriaTextFieldProps, ref: RefObject<Element>): TextFieldAria;71function useNumberField(props: AriaNumberFieldProps, ref: RefObject<Element>): NumberFieldAria;72function useSearchField(props: AriaSearchFieldProps, ref: RefObject<Element>): SearchFieldAria;73function useCheckbox(props: AriaCheckboxProps, ref: RefObject<Element>): CheckboxAria;74function useCheckboxGroup(props: AriaCheckboxGroupProps, ref: RefObject<Element>): CheckboxGroupAria;75function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, ref: RefObject<Element>): CheckboxAria;76function useRadio(props: AriaRadioProps, ref: RefObject<Element>): RadioAria;77function useRadioGroup(props: AriaRadioGroupProps, ref: RefObject<Element>): RadioGroupAria;78function useSwitch(props: AriaSwitchProps, ref: RefObject<Element>): SwitchAria;79function useColorArea(props: AriaColorAreaProps, ref: RefObject<Element>): ColorAreaAria;80function useColorChannelField(props: AriaColorChannelFieldProps, ref: RefObject<Element>): ColorChannelFieldAria;81function useColorField(props: AriaColorFieldProps, ref: RefObject<Element>): ColorFieldAria;82function useColorSlider(props: AriaColorSliderProps, ref: RefObject<Element>): ColorSliderAria;83function useColorSwatch(props: AriaColorSwatchProps, ref: RefObject<Element>): ColorSwatchAria;84function useColorWheel(props: AriaColorWheelOptions, ref: RefObject<Element>): ColorWheelAria;85function useProgressBar(props: AriaProgressBarProps, ref: RefObject<Element>): ProgressBarAria;86function useMeter(props: AriaMeterProps, ref: RefObject<Element>): MeterAria;87function useSlider(props: AriaSliderProps, ref: RefObject<Element>): SliderAria;88function useSliderThumb(props: AriaSliderThumbProps, state: SliderState, ref: RefObject<Element>): SliderThumbAria;89function useField(props: AriaFieldProps, ref: RefObject<Element>): FieldAria;90function useLabel(props: LabelAriaProps, ref: RefObject<Element>): LabelAria;91```9293[Form Controls](./form-controls.md)9495### Selection Controls9697Components for selecting from lists of options, including listboxes, comboboxes, and menus.9899```typescript { .api }100function useListBox(props: AriaListBoxProps, state: ListState<T>, ref: RefObject<Element>): ListBoxAria;101function useComboBox(props: AriaComboBoxProps, state: ComboBoxState<T>, ref: RefObject<Element>): ComboBoxAria;102function useSelect(props: AriaSelectProps, state: SelectState<T>, ref: RefObject<Element>): SelectAria;103function useMenu(props: AriaMenuProps, state: TreeState<T>, ref: RefObject<Element>): MenuAria;104```105106[Selection Controls](./selection-controls.md)107108### Date and Time109110Date and time input components with internationalization and accessibility support.111112```typescript { .api }113function useDatePicker(props: AriaDatePickerProps, state: DatePickerState, ref: RefObject<Element>): DatePickerAria;114function useDateField(props: AriaDateFieldProps, state: DateFieldState, ref: RefObject<Element>): DateFieldAria;115function useCalendar(props: AriaCalendarProps, state: CalendarState, ref: RefObject<Element>): CalendarAria;116function useTimeField(props: AriaTimeFieldProps, state: TimeFieldState, ref: RefObject<Element>): TimeFieldAria;117```118119[Date and Time](./date-time.md)120121### Layout and Navigation122123Components for organizing and navigating content including tabs, breadcrumbs, and tables.124125```typescript { .api }126function useTabList(props: AriaTabListProps, state: TabListState<T>, ref: RefObject<Element>): TabListAria;127function useBreadcrumbs(props: AriaBreadcrumbsProps, ref: RefObject<Element>): BreadcrumbsAria;128function useTable(props: AriaTableProps, state: TableState<T>, ref: RefObject<Element>): GridAria;129function useTree(props: AriaTreeProps, state: TreeState<T>, ref: RefObject<Element>): TreeAria;130```131132[Layout and Navigation](./layout-navigation.md)133134### Overlays and Modals135136Overlay components including dialogs, popovers, tooltips, and modals with proper focus management.137138```typescript { .api }139function useDialog(props: AriaDialogProps, ref: RefObject<Element>): DialogAria;140function usePopover(props: AriaPopoverProps, state: PopoverState, ref: RefObject<Element>): PopoverAria;141function useTooltip(props: AriaTooltipProps, state: TooltipTriggerState): TooltipAria;142function useModal(options?: AriaModalOptions): ModalAria;143```144145[Overlays and Modals](./overlays-modals.md)146147### Interactions148149Low-level interaction hooks for handling user input across different devices and interaction models.150151```typescript { .api }152function usePress(props: PressHookProps): PressResult;153function useHover(props: HoverProps): HoverResult;154function useFocus(props: FocusProps): FocusResult;155function useKeyboard(props: KeyboardProps): KeyboardResult;156function useDrag(options: DragOptions): DragResult;157function useDrop(options: DropOptions): DropResult;158```159160[Interactions](./interactions.md)161162### Focus Management163164Advanced focus management including focus rings, focus scopes, and focus restoration.165166```typescript { .api }167function useFocusRing(props?: AriaFocusRingProps): FocusRingAria;168function useFocusManager(): FocusManager;169function useFocusable(props: FocusableOptions, domRef: RefObject<Element>): FocusableAria;170```171172[Focus Management](./focus-management.md)173174### Internationalization175176Comprehensive i18n support with locale-aware formatting, RTL layout, and localization utilities.177178```typescript { .api }179function useLocale(): { locale: string; direction: 'ltr' | 'rtl' };180function useDateFormatter(options: DateFormatterOptions): DateFormatter;181function useNumberFormatter(options: Intl.NumberFormatOptions): Intl.NumberFormat;182function useCollator(options: Intl.CollatorOptions): Intl.Collator;183```184185[Internationalization](./internationalization.md)186187### Toast Notifications188189Toast notification system for displaying temporary messages and alerts.190191```typescript { .api }192function useToast(props: AriaToastProps, state: ToastState, ref: RefObject<Element>): ToastAria;193function useToastRegion(props: AriaToastRegionProps, state: ToastRegionState, ref: RefObject<Element>): ToastRegionAria;194```195196[Toast Notifications](./toast-notifications.md)197198### Tags199200Tag components for displaying and managing collections of labels or categories.201202```typescript { .api }203function useTag(props: AriaTagProps, state: TagState, ref: RefObject<Element>): TagAria;204function useTagGroup(props: AriaTagGroupProps, state: TagGroupState, ref: RefObject<Element>): TagGroupAria;205```206207[Tags](./tags.md)208209### Drag and Drop210211Comprehensive drag and drop system for building interactive interfaces with accessible keyboard navigation.212213```typescript { .api }214function useDrag(options: DragOptions): DragResult;215function useDrop(options: DropOptions): DropResult;216function useDraggableCollection(props: DraggableCollectionProps): DraggableCollectionResult;217function useDroppableCollection(props: DroppableCollectionProps): DroppableCollectionResult;218function useDraggableItem(props: DraggableItemProps): DraggableItemResult;219function useDroppableItem(props: DroppableItemProps): DroppableItemResult;220function useDropIndicator(props: DropIndicatorProps): DropIndicatorResult;221function useClipboard(options: ClipboardOptions): ClipboardResult;222```223224[Drag and Drop](./drag-drop.md)225226### Disclosure227228Disclosure components for expandable content sections.229230```typescript { .api }231function useDisclosure(props: AriaDisclosureProps, ref: RefObject<Element>): DisclosureAria;232```233234### Landmarks235236Landmark components for improving page navigation and structure.237238```typescript { .api }239function useLandmark(props: AriaLandmarkProps, ref: RefObject<Element>): LandmarkAria;240```241242### Server-Side Rendering243244SSR utilities for handling server-side rendering scenarios and hydration.245246```typescript { .api }247function SSRProvider(props: SSRProviderProps): JSX.Element;248function useIsSSR(): boolean;249```250251### Visually Hidden252253Utilities for hiding content visually while keeping it accessible to screen readers.254255```typescript { .api }256function VisuallyHidden(props: VisuallyHiddenProps): JSX.Element;257function useVisuallyHidden(props?: VisuallyHiddenOptions): VisuallyHiddenAria;258```259260### Utilities261262Utility hooks and functions for common React Aria patterns and prop management.263264```typescript { .api }265function mergeProps(...props: any[]): any;266function chain(...callbacks: any[]): (...args: any[]) => void;267function useId(defaultId?: string): string;268function useObjectRef<T>(forwardedRef: ForwardedRef<T>): RefObject<T>;269function RouterProvider(props: RouterProviderProps): JSX.Element;270```271272[Utilities](./utilities.md)273274## Common Types275276```typescript { .api }277type Key = string | number;278279type Orientation = 'horizontal' | 'vertical';280281type SelectionMode = 'none' | 'single' | 'multiple';282283type ValidationState = 'valid' | 'invalid';284285type NecessityIndicator = 'icon' | 'label';286287interface PressEvent {288type: 'pressstart' | 'pressend' | 'pressup' | 'press';289pointerType: 'mouse' | 'pen' | 'touch' | 'keyboard' | 'virtual';290target: Element;291shiftKey: boolean;292ctrlKey: boolean;293metaKey: boolean;294altKey: boolean;295}296297interface HoverEvent {298type: 'hoverstart' | 'hoverend';299pointerType: 'mouse' | 'pen';300target: Element;301}302303interface FocusEvent {304type: 'focus' | 'blur';305target: Element;306relatedTarget: Element | null;307}308309interface KeyboardEvent {310type: 'keydown' | 'keyup';311key: string;312code: string;313shiftKey: boolean;314ctrlKey: boolean;315metaKey: boolean;316altKey: boolean;317}318319interface DOMAttributes<T = Element> {320[key: string]: any;321}322323interface RefObject<T> {324current: T | null;325}326327type ForwardedRef<T> = ((instance: T | null) => void) | MutableRefObject<T | null> | null;328329interface MutableRefObject<T> {330current: T;331}332333interface Collection<T> {334getKeys(): Iterable<Key>;335getItem(key: Key): T | null;336getSize(): number;337}338339interface SelectionManager {340selectedKeys: Set<Key>;341isSelected(key: Key): boolean;342select(key: Key): void;343selectAll(): void;344clearSelection(): void;345}346```