useRovingFocus
Arrow-key navigation through a group of items, the WAI-ARIA way: the arrows of the orientation, Home and End, optional wrap and type-ahead, disabled items skipped. Roving tabindex for tabs and toolbars (one Tab stop), or an active index for a listbox or combobox where focus stays in an input. Select, the docs tabs, the preset switcher and the ⌘K palette use it.
Install: pnpm add-composable useRovingFocus
Toolbar and listbox
Tab into the toolbar once, then use the arrows. In the listbox, focus stays on the list and aria-activedescendant moves; type "bl" to land on Blackberry, then Blueberry.
API
count(MaybeRefOrGetter<number>): How many items. The index is pulled back the moment the list shrinks.orientation('horizontal' | 'vertical' | 'both'): Which arrows move.loop(boolean): Wrap from the last item to the first and back.disabled((index) => boolean): Items to skip.label((index) => string): Turns on type-ahead: typed letters jump to the next item starting with them. Leave it off when typing goes into a search box.initial(number): Starting index; -1 for none.container(Ref<HTMLElement | null>): Roving-tabindex mode: moving focuses the item. Items are found by ARIA role (tab, radio, option, menuitem…) or itemSelector.dir('ltr' | 'rtl' | 'auto'): Direction of the left and right arrows. auto reads it from container, so in RTL ArrowLeft moves to the next item (APG).onChange((index) => void): After a key moves the index: automatic tab activation, select-on-move.active(Ref<number>): Returned. The active index, -1 when empty.onKeydown((e: KeyboardEvent) => boolean): Returned. Bind on the container or the input; returns whether it used the key (and then prevents its default).tabindex((index) => 0 | -1): Returned. Bind on each item in roving mode.set((index, { focus? }) => void): Returned. Move the index, e.g. on click; focus: false keeps focus where it is.