createSelectableCollectionNavigation
Add accessible keyboard navigation (arrow keys, Home/End, RTL) for tabs, radio groups, and listboxes.
createSelectableCollectionNavigation adds keyboard navigation (Arrow Up/Down/Left/Right, Home, End) and activation handling to a collection of selectable items such as Tabs, Radio Groups, and Listboxes.
Import#
Signature#
TValue can be a string, number, or any other non-null value. Items compare by ===.
Usage Example#
src/CustomTabs.tsx
Key Bindings#
The orientation you pass to onNavigationKeyDown decides which arrow keys navigate.
- ArrowLeft / ArrowRight: Move to the previous / next item in horizontal collections. The keys swap in RTL.
- ArrowUp / ArrowDown: Move to the previous / next item in vertical collections.
- Home / End: Jump to the first / last enabled item.
- Enter / Space: Select the current item unless it is disabled, in both activation modes.
- Automatic vs manual: In
automaticmode, arrow keys, Home, and End move focus and select in one step. Inmanualmode, they only move focus.
Without a current item, the next key goes to the first enabled item and the previous key to the last. Disabled items are skipped. Without loop, navigation stops at the ends.