useRovingTabIndex
Implements the WAI-ARIA roving tabIndex keyboard navigation pattern for composite widgets.
The useRovingTabIndex hook implements the WAI-ARIA roving tabIndex pattern for toolbars, tablists, menus, and radio groups, managing arrow-key navigation, Home/End shortcuts, looping, disabled item skipping, and DOM focus synchronization.
Installation
Usage
Examples
Horizontal Toolbar with Disabled Items
Pass { disabled: true } to getItemProps so arrow keys automatically skip disabled buttons while navigating.
Vertical Menu List
Set orientation: "vertical" to navigate items using ArrowUp and ArrowDown.
API Reference
UseRovingTabIndexOptions
Configuration options for orientation, looping, and controlled/uncontrolled active index.
count?activeIndex?defaultActiveIndex?orientation?loop?rtl?onActiveIndexChange?(indexnumberRovingItemOptions
Per-item options passed to getItemProps(index, options).
disabled?onKeyDown?onKeyDown handler composed with roving keyboard navigation.(eventReactKeyboardEvent<T>onFocus?onFocus handler composed with active index synchronization.(eventReactFocusEvent<T>RovingTabIndexItemProps
Props returned by getItemProps to spread onto each focusable item element.
refrequirednodeT | nulltabIndexrequired0 for the active tabbable item, -1 for all other items.onKeyDownrequiredeventReactKeyboardEvent<T>onFocusrequiredeventReactFocusEvent<T>UseRovingTabIndexReturn
Active index state and helper methods returned by the hook.
activeIndexsetActiveIndexindexnumberfocusItemindexnumbergetItemPropsref, tabIndex, onKeyDown, and onFocus props for an item at index.indexnumberoptions?RovingItemOptions<T>