- 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
layout-navigation.md docs/
1# Layout and Navigation23Components for organizing and navigating content including tabs, breadcrumbs, tables, trees, and other structural elements. All components provide proper keyboard navigation, screen reader support, and ARIA semantics.45## Capabilities67### Tabs89Provides tab interface behavior with keyboard navigation and content management.1011```typescript { .api }12/**13* Provides tab list behavior and accessibility14* @param props - Tab list configuration15* @param state - Tab list state16* @param ref - Ref to the tab list element17* @returns Tab list props and state18*/19function useTabList<T>(props: AriaTabListProps<T>, state: TabListState<T>, ref: RefObject<Element>): TabListAria;2021/**22* Provides individual tab behavior23* @param props - Tab configuration24* @param state - Tab list state25* @param ref - Ref to the tab element26* @returns Tab props and state27*/28function useTab(props: AriaTabProps, state: TabListState<T>, ref: RefObject<Element>): TabAria;2930/**31* Provides tab panel behavior for content areas32* @param props - Tab panel configuration33* @param state - Tab list state34* @param ref - Ref to the panel element35* @returns Tab panel props36*/37function useTabPanel(props: AriaTabPanelProps, state: TabListState<T>, ref: RefObject<Element>): TabPanelAria;3839interface AriaTabListProps<T> extends AriaTabListOptions<T> {40/** Items in the tab list */41items?: Iterable<T>;42/** Currently selected key */43selectedKey?: Key | null;44/** Default selected key (uncontrolled) */45defaultSelectedKey?: Key | null;46/** Handler called when selection changes */47onSelectionChange?: (key: Key) => void;48/** Orientation of the tab list */49orientation?: Orientation;50/** Whether tabs are disabled */51isDisabled?: boolean;52/** Keyboard activation mode */53keyboardActivation?: 'automatic' | 'manual';54/** Disabled keys */55disabledKeys?: Iterable<Key>;56}5758interface TabListAria {59/** Props for the tab list element */60tabListProps: DOMAttributes<Element>;61}6263interface AriaTabProps {64/** Key for the tab */65key?: Key;66/** Whether the tab is disabled */67isDisabled?: boolean;68}6970interface TabAria {71/** Props for the tab element */72tabProps: DOMAttributes<Element>;73/** Whether the tab is selected */74isSelected: boolean;75/** Whether the tab is disabled */76isDisabled: boolean;77/** Whether the tab is pressed */78isPressed: boolean;79}8081interface AriaTabPanelProps {82/** Key for the tab panel */83key?: Key;84}8586interface TabPanelAria {87/** Props for the tab panel element */88tabPanelProps: DOMAttributes<Element>;89}90```9192### Breadcrumbs9394Provides breadcrumb navigation behavior with proper accessibility and structure.9596```typescript { .api }97/**98* Provides breadcrumbs container behavior and accessibility99* @param props - Breadcrumbs configuration100* @param ref - Ref to the breadcrumbs element101* @returns Breadcrumbs props102*/103function useBreadcrumbs(props: AriaBreadcrumbsProps, ref: RefObject<Element>): BreadcrumbsAria;104105/**106* Provides individual breadcrumb item behavior107* @param props - Breadcrumb item configuration108* @param ref - Ref to the breadcrumb element109* @returns Breadcrumb item props110*/111function useBreadcrumbItem(props: AriaBreadcrumbItemProps, ref: RefObject<Element>): BreadcrumbItemAria;112113interface AriaBreadcrumbsProps {114/** Children breadcrumb items */115children: ReactNode;116/** Whether breadcrumbs are disabled */117isDisabled?: boolean;118}119120interface BreadcrumbsAria {121/** Props for the breadcrumbs nav element */122navProps: HTMLAttributes<HTMLElement>;123/** Props for the breadcrumbs list element */124listProps: HTMLAttributes<HTMLOListElement>;125}126127interface AriaBreadcrumbItemProps {128/** Children content */129children: ReactNode;130/** Whether this is the current page */131isCurrent?: boolean;132/** Whether the item is disabled */133isDisabled?: boolean;134/** Handler called when the item is activated */135onAction?: () => void;136/** Href for link behavior */137href?: string;138/** Target for link */139target?: string;140/** Rel for link */141rel?: string;142}143144interface BreadcrumbItemAria {145/** Props for the breadcrumb item element */146itemProps: HTMLAttributes<HTMLLIElement>;147/** Props for the breadcrumb link element */148linkProps: AnchorHTMLAttributes<HTMLAnchorElement> | ButtonHTMLAttributes<HTMLButtonElement>;149/** Whether this is the current page */150isCurrent: boolean;151/** Whether the item is disabled */152isDisabled: boolean;153}154```155156### Table157158Provides table behavior with selection, sorting, and keyboard navigation.159160```typescript { .api }161/**162* Provides table behavior and accessibility163* @param props - Table configuration164* @param state - Table state165* @param ref - Ref to the table element166* @returns Table props and state167*/168function useTable<T>(props: AriaTableProps<T>, state: TableState<T>, ref: RefObject<Element>): GridAria;169170/**171* Provides table row behavior172* @param props - Table row configuration173* @param state - Table state174* @param ref - Ref to the row element175* @returns Table row props and state176*/177function useTableRow<T>(props: GridRowProps<T>, state: TableState<T>, ref: RefObject<Element>): GridRowAria;178179/**180* Provides table cell behavior181* @param props - Table cell configuration182* @param state - Table state183* @param ref - Ref to the cell element184* @returns Table cell props185*/186function useTableCell(props: AriaTableCellProps, state: TableState<T>, ref: RefObject<Element>): TableCellAria;187188/**189* Provides table column header behavior with sorting190* @param props - Column header configuration191* @param state - Table state192* @param ref - Ref to the header element193* @returns Column header props and state194*/195function useTableColumnHeader<T>(props: AriaTableColumnHeaderProps, state: TableState<T>, ref: RefObject<Element>): TableColumnHeaderAria;196197/**198* Provides table row group behavior (thead, tbody, tfoot)199* @param ref - Ref to the row group element200* @returns Row group props201*/202function useTableRowGroup(ref: RefObject<Element>): TableHeaderRowAria;203204/**205* Provides table header row behavior206* @param props - Header row configuration207* @param state - Table state208* @param ref - Ref to the header row element209* @returns Header row props210*/211function useTableHeaderRow<T>(props: {}, state: TableState<T>, ref: RefObject<Element>): TableHeaderRowAria;212213/**214* Provides select all checkbox behavior for tables215* @param props - Select all checkbox configuration216* @param state - Table state217* @param ref - Ref to the checkbox element218* @returns Select all checkbox props219*/220function useTableSelectAllCheckbox<T>(props: AriaTableSelectionCheckboxProps, state: TableState<T>, ref: RefObject<Element>): TableSelectAllCheckboxAria;221222/**223* Provides selection checkbox behavior for table rows224* @param props - Selection checkbox configuration225* @param state - Table state226* @param ref - Ref to the checkbox element227* @returns Selection checkbox props228*/229function useTableSelectionCheckbox<T>(props: AriaTableSelectionCheckboxProps, state: TableState<T>, ref: RefObject<Element>): TableSelectionCheckboxAria;230231/**232* Provides column resize behavior for table columns233* @param props - Column resize configuration234* @param state - Table state235* @param ref - Ref to the resize handle element236* @returns Column resize props and state237*/238function useTableColumnResize<T>(props: AriaTableColumnResizeProps, state: TableState<T>, ref: RefObject<Element>): TableColumnResizeAria;239240interface AriaTableProps<T> {241/** Items in the table */242items?: Iterable<T>;243/** Selection mode */244selectionMode?: SelectionMode;245/** Selected keys */246selectedKeys?: 'all' | Iterable<Key>;247/** Default selected keys (uncontrolled) */248defaultSelectedKeys?: 'all' | Iterable<Key>;249/** Handler called when selection changes */250onSelectionChange?: (keys: Selection) => void;251/** Disabled keys */252disabledKeys?: Iterable<Key>;253/** Sort descriptor */254sortDescriptor?: SortDescriptor;255/** Handler called when sort changes */256onSortChange?: (descriptor: SortDescriptor) => void;257/** Handler called when a row is activated */258onAction?: (key: Key) => void;259/** Handler called on row expansion */260onExpandedChange?: (keys: Set<Key>) => void;261/** Whether rows can be resized */262allowsResizing?: boolean;263/** Whether column headers are sticky */264stickyColumnHeaders?: boolean;265}266267interface GridAria {268/** Props for the table grid element */269gridProps: DOMAttributes<Element>;270}271```272273### Tree274275Provides tree view behavior with hierarchical navigation and expansion.276277```typescript { .api }278/**279* Provides tree behavior and accessibility280* @param props - Tree configuration281* @param state - Tree state282* @param ref - Ref to the tree element283* @returns Tree props and state284*/285function useTree<T>(props: AriaTreeProps<T>, state: TreeState<T>, ref: RefObject<Element>): TreeAria;286287/**288* Provides tree item behavior with expansion and selection289* @param props - Tree item configuration290* @param state - Tree state291* @param ref - Ref to the tree item element292* @returns Tree item props and state293*/294function useTreeItem<T>(props: AriaTreeItemOptions<T>, state: TreeState<T>, ref: RefObject<Element>): TreeItemAria;295296interface AriaTreeProps<T> extends TreeProps<T> {297/** Items in the tree */298items?: Iterable<T>;299/** Selection mode */300selectionMode?: SelectionMode;301/** Selected keys */302selectedKeys?: 'all' | Iterable<Key>;303/** Default selected keys (uncontrolled) */304defaultSelectedKeys?: 'all' | Iterable<Key>;305/** Handler called when selection changes */306onSelectionChange?: (keys: Selection) => void;307/** Expanded keys */308expandedKeys?: Iterable<Key>;309/** Default expanded keys (uncontrolled) */310defaultExpandedKeys?: Iterable<Key>;311/** Handler called when expansion changes */312onExpandedChange?: (keys: Set<Key>) => void;313/** Disabled keys */314disabledKeys?: Iterable<Key>;315/** Handler called when an item is activated */316onAction?: (key: Key) => void;317/** Whether the tree is disabled */318isDisabled?: boolean;319/** Auto-focus behavior */320autoFocus?: boolean | FocusStrategy;321/** Whether focus should wrap */322shouldFocusWrap?: boolean;323}324325interface TreeAria {326/** Props for the tree element */327treeProps: DOMAttributes<Element>;328}329330interface AriaTreeItemOptions<T> {331/** Key for the tree item */332key: Key;333/** Whether the item is disabled */334isDisabled?: boolean;335/** Whether the item should be focused */336shouldSelectOnPressUp?: boolean;337/** Whether the item should use virtual focus */338shouldUseVirtualFocus?: boolean;339/** Ref for the tree item */340ref?: RefObject<Element>;341}342343interface TreeItemAria {344/** Props for the tree item element */345rowProps: DOMAttributes<Element>;346/** Props for the tree item content */347gridCellProps: DOMAttributes<Element>;348/** Props for the expand button */349buttonProps: ButtonHTMLAttributes<HTMLButtonElement>;350/** Props for the checkbox */351checkboxProps: InputHTMLAttributes<HTMLInputElement>;352/** Whether the item is selected */353isSelected: boolean;354/** Whether the item is expanded */355isExpanded: boolean;356/** Whether the item is disabled */357isDisabled: boolean;358/** Whether the item is pressed */359isPressed: boolean;360/** Level of the item in the tree */361level: number;362/** Whether the item has child items */363hasChildRows: boolean;364}365```366367### Link368369Provides link behavior with proper accessibility and routing integration.370371```typescript { .api }372/**373* Provides link behavior and accessibility374* @param props - Link configuration375* @param ref - Ref to the link element376* @returns Link props and state377*/378function useLink(props: AriaLinkOptions, ref: RefObject<Element>): LinkAria;379380interface AriaLinkOptions {381/** Whether the link is disabled */382isDisabled?: boolean;383/** Handler called when the link is activated */384onPress?: (e: PressEvent) => void;385/** Element type to render as */386elementType?: React.ElementType;387}388389interface LinkAria {390/** Props for the link element */391linkProps: AnchorHTMLAttributes<HTMLAnchorElement>;392/** Whether the link is pressed */393isPressed: boolean;394}395```396397### Tags398399Provides tag group behavior for managing collections of tags or chips.400401```typescript { .api }402/**403* Provides tag group behavior and accessibility404* @param props - Tag group configuration405* @param state - Tag group state406* @param ref - Ref to the tag group element407* @returns Tag group props and state408*/409function useTagGroup<T>(props: AriaTagGroupProps<T>, state: ListState<T>, ref: RefObject<Element>): TagGroupAria;410411/**412* Provides individual tag behavior413* @param props - Tag configuration414* @param state - Tag group state415* @param ref - Ref to the tag element416* @returns Tag props and state417*/418function useTag<T>(props: AriaTagProps, state: ListState<T>, ref: RefObject<Element>): TagAria;419420interface AriaTagGroupProps<T> {421/** Items in the tag group */422items?: Iterable<T>;423/** Selected keys */424selectedKeys?: 'all' | Iterable<Key>;425/** Default selected keys (uncontrolled) */426defaultSelectedKeys?: 'all' | Iterable<Key>;427/** Handler called when selection changes */428onSelectionChange?: (keys: Selection) => void;429/** Handler called when a tag is removed */430onRemove?: (keys: Set<Key>) => void;431/** Whether tags can be removed */432allowsRemoving?: boolean;433/** Whether the tag group is disabled */434isDisabled?: boolean;435/** Label for the tag group */436label?: ReactNode;437/** Description for the tag group */438description?: ReactNode;439/** Error message for the tag group */440errorMessage?: ReactNode;441}442443interface TagGroupAria {444/** Props for the tag group element */445gridProps: DOMAttributes<Element>;446/** Props for the label element */447labelProps: DOMAttributes<Element>;448/** Props for the description element */449descriptionProps: DOMAttributes<Element>;450/** Props for the error message element */451errorMessageProps: DOMAttributes<Element>;452}453454interface AriaTagProps {455/** Key for the tag */456key?: Key;457/** Whether the tag is disabled */458isDisabled?: boolean;459/** Text content of the tag */460textContent?: string;461/** Whether the tag can be removed */462allowsRemoving?: boolean;463}464465interface TagAria {466/** Props for the tag row element */467rowProps: DOMAttributes<Element>;468/** Props for the tag content element */469gridCellProps: DOMAttributes<Element>;470/** Props for the remove button */471removeButtonProps: ButtonHTMLAttributes<HTMLButtonElement>;472/** Props for the tag description */473descriptionProps: DOMAttributes<Element>;474/** Whether the tag is selected */475isSelected: boolean;476/** Whether the tag is disabled */477isDisabled: boolean;478/** Whether the tag is pressed */479isPressed: boolean;480/** Whether the remove button is pressed */481isRemoveButtonPressed: boolean;482/** Allow removing the tag */483allowsRemoving: boolean;484}485```486487### Separator488489Provides separator element behavior for dividing content sections.490491```typescript { .api }492/**493* Provides separator behavior and accessibility494* @param props - Separator configuration495* @param ref - Ref to the separator element496* @returns Separator props497*/498function useSeparator(props: SeparatorProps, ref: RefObject<Element>): SeparatorAria;499500interface SeparatorProps {501/** Orientation of the separator */502orientation?: Orientation;503/** Element type to render */504elementType?: string;505}506507interface SeparatorAria {508/** Props for the separator element */509separatorProps: DOMAttributes<Element>;510}511```512513### Landmark514515Provides landmark region behavior for page structure and navigation.516517```typescript { .api }518/**519* Provides landmark behavior and accessibility520* @param props - Landmark configuration521* @param ref - Ref to the landmark element522* @returns Landmark props and controller523*/524function useLandmark(props: AriaLandmarkProps, ref: RefObject<Element>): LandmarkAria;525526interface AriaLandmarkProps {527/** ARIA landmark role */528role?: AriaLandmarkRole;529/** Accessible name for the landmark */530'aria-label'?: string;531/** ID of element that labels the landmark */532'aria-labelledby'?: string;533}534535interface LandmarkAria {536/** Props for the landmark element */537landmarkProps: DOMAttributes<Element>;538/** Landmark controller for managing focus */539landmarkController: LandmarkController;540}541542type AriaLandmarkRole =543| 'banner'544| 'complementary'545| 'contentinfo'546| 'form'547| 'main'548| 'navigation'549| 'region'550| 'search';551552interface LandmarkController {553/** Navigate to the next landmark */554nextLandmark(): void;555/** Navigate to the previous landmark */556previousLandmark(): void;557/** Get all landmarks on the page */558getLandmarks(): Element[];559}560```561562## Types563564```typescript { .api }565interface TabListState<T> {566/** Collection of tab items */567collection: Collection<Node<T>>;568/** Currently selected key */569selectedKey: Key | null;570/** Set the selected key */571setSelectedKey(key: Key): void;572/** Selected item */573selectedItem: Node<T> | null;574}575576interface TableState<T> {577/** Collection of table items */578collection: Collection<Node<T>>;579/** Set of selected keys */580selectedKeys: Selection;581/** Set the selected keys */582setSelectedKeys(keys: Selection): void;583/** Sort descriptor */584sortDescriptor: SortDescriptor | null;585/** Set the sort descriptor */586setSortDescriptor(descriptor: SortDescriptor): void;587/** Set of expanded keys */588expandedKeys: Set<Key>;589/** Toggle expansion of a key */590toggleExpanded(key: Key): void;591}592593interface TreeState<T> {594/** Collection of tree items */595collection: Collection<Node<T>>;596/** Set of selected keys */597selectedKeys: Selection;598/** Set the selected keys */599setSelectedKeys(keys: Selection): void;600/** Set of expanded keys */601expandedKeys: Set<Key>;602/** Toggle expansion of a key */603toggleExpanded(key: Key): void;604/** Currently focused key */605focusedKey: Key | null;606/** Set the focused key */607setFocusedKey(key: Key): void;608}609610interface SortDescriptor {611/** Column key to sort by */612column: Key;613/** Sort direction */614direction: 'ascending' | 'descending';615}616```