ListBox
A headless selectable list primitive with keyboard navigation, single and multiple selection, and controlled or uncontrolled state.
Selected: banana
Anatomy
ListBox.Root is the container that owns selection state and keyboard interactions; each option is a ListBox.Item with a unique id.
<script>
import { ListBox } from '@human-kit/ui';
</script>
<ListBox.Root aria-label="Options">
<ListBox.Item id="1">Option 1</ListBox.Item>
</ListBox.Root>Multiple selection
Set selectionMode="multiple" to allow more than one selected item. selectionBehavior controls what happens on repeat selection: "toggle" (default) deselects, "replace" always replaces the selection. Press Ctrl+A to select everything.
2 selected
Disabled items
Use disabled on ListBox.Item (or disabledKeys on the root) to make individual options non-interactive. Disabled items are skipped by keyboard navigation and styled through data-disabled.
Usage guidelines
- Use
ListBox.Rootas the container for selection state and keyboard interactions, and render each option withListBox.Item. - Use
value/onChangefor controlled selection anddefaultValuefor uncontrolled initial selection. Values are sets of item ids. - Use
selectionBehavior="replace"when picking an option should always replace the current selection instead of toggling it. - Use
disabledon individual items ordisabledKeyson the root to make options non-selectable. - Provide
aria-labelon the root when there is no visible label.
Accessibility
ListBox.Rootrendersrole="listbox"witharia-multiselectablein multiple mode; eachListBox.Itemrendersrole="option"witharia-selected.- Arrow keys move focus between items;
Home/Endjump to the first or last item. Space/Enterselect the focused item;Ctrl+Aselects all items in multiple mode.- Every visual state (
data-selected,data-focused,data-focus-visible,data-hovered,data-pressed,data-disabled) is exposed as a data attribute for styling.
API reference
Root
The listbox container. Manages option registration, selection state, focus, and keyboard navigation.
* required. Native HTML attributes of the underlying element are also accepted.
Item
A selectable option. Registers itself with the root and exposes selected, focused, hovered, pressed, and disabled states through data attributes.
* required. Native HTML attributes of the underlying element are also accepted.