Skip to content

useListFocus

@astryxdesign/core v0.7.1 · useListFocus

Usage ​

Manages keyboard navigation within a linear list following WAI-ARIA menu, listbox, and toolbar patterns. Supports arrow key navigation (vertical, horizontal, or both), Home/End for boundaries, optional wrap-around, RTL, and Escape to close. Opt into hasRovingTabIndex for composite widgets (toolbars, segmented controls, tab strips) that own a single tab stop. Suitable for dropdown menus, toolbars, and any 1D focusable list.

Attach listRef to the container, handleKeyDown to its keys, and handleFocus to its focus event. handleFocus is a no-op unless hasRovingTabIndex is on, so it is always safe to attach.

ts
import { useListFocus } from '@astryx-vue/core'

Best practices ​

GuidancePractices
DoSet orientation to 'horizontal' for toolbars and tab bars, 'vertical' for dropdown menus.
DoProvide an onEscape callback for menus/dropdowns to return focus to the trigger.
DoEnable hasRovingTabIndex (and hasCaretGuard when the widget can contain text inputs) for toolbar-style composites that should be a single tab stop.
Don'tUse for 2D grid navigation; prefer useGridRovingFocus for grids and calendars.