Listbox
An accessible listbox with single and multiple selection, grouping, and typeahead.
Features
- Single or multiple
- Groups and nesting
- Typeahead
- Controlled or uncontrolled
- Managed focus
Installation
npm install @ariaui/listbox
Examples
Three playgrounds from the legacy docs: a compact uncontrolled list with defaultValue, a controlled single-select with groups and a Listbox.Sub, and the same layout with selectionMode="multiple" plus a selection readout.
Styling uses semantic tokens via listboxExampleTokens.ts; checkmarks use @heroicons/react/24/solid. Controlled examples use exampleSource fences so hooks stay readable in the snippet.
Basic
Uncontrolled list with a default selected option.
No preview output yet.
Max visible items
Listbox with a fixed-height scroll region for a long option list.
No preview output yet.
Single selection with submenu
Grouped options with a nested submenu and controlled selection.
No preview output yet.
Multiple selection with submenu
Multi-select listbox with nested options and a live selection readout.
No preview output yet.
Anatomy
import * as Listbox from "@ariaui/listbox";
export default function Example() {
return (
<Listbox.Root>
<Listbox.Label />
<Listbox.Content>
<Listbox.Viewport>
<Listbox.Group>
<Listbox.GroupLabel />
<Listbox.Option />
</Listbox.Group>
<Listbox.Sub>
<Listbox.SubTrigger />
<Listbox.SubContent>
<Listbox.Option />
</Listbox.SubContent>
</Listbox.Sub>
</Listbox.Viewport>
</Listbox.Content>
</Listbox.Root>
);
}
API Reference
Root
Selection state provider with a div host; providers remain outside an adopted host.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
selectionMode | 'single' | 'multiple' | 'single' |
value | string | string[] | — |
defaultValue | string | string[] | — |
onValueChange | (value: string | string[]) => void | — |
offset | { x: number; y: number } | { x: 0, y: 0 } |
Label
Native label naming Content through its live effective ID.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Content
Focusable listbox surface owning live option registration and keyboard navigation.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Attribute | Values |
|---|---|
| role | listbox |
| aria-labelledby | Effective Label ID, when present |
| aria-multiselectable | true | false |
| aria-activedescendant | ID of the active connected option |
Viewport
Optional non-roled native overflow box inside Content.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
maxVisibleItems* | number | — |
| Attribute | Values |
|---|---|
| [data-listbox-viewport] | Empty attribute |
Option
Selectable div option; registration follows the current physical host and DOM order.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
value* | string | — |
disabled | boolean | false |
| Attribute | Values |
|---|---|
| role | option |
| aria-selected | true | false |
| aria-disabled | true when disabled |
| [data-active] | true | false |
Group
Div group named by the current GroupLabel host.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Attribute | Values |
|---|---|
| role | group |
| aria-labelledby | Effective GroupLabel ID, when present |
GroupLabel
Div label whose live ID names its group.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Sub
State-only submenu provider. Renders no DOM and has no asChild prop.
| Prop | Type | Default |
|---|---|---|
offset | { x: number; y: number } | { x: 0, y: 0 } |
SubTrigger
Div option that opens a submenu with click, hover, ArrowRight, Enter or Space.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
disabled | boolean | false |
| Attribute | Values |
|---|---|
| role | option |
| aria-expanded | true | false |
| aria-haspopup | listbox |
| [data-active] | true | false |
SubContent
Portalled submenu collection; mounts only while the submenu is open.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Attribute | Values |
|---|---|
| role | listbox |
| aria-labelledby | Effective SubTrigger ID |
| aria-activedescendant | ID of the active connected option |
Keyboard
| Shortcut | Action |
|---|---|
| ↓ | Move focus to the next option. Wraps to first. |
| ↑ | Move focus to the previous option. Wraps to last. |
| Home | Move focus to the first option. |
| End | Move focus to the last option. |
| Enter | Select the focused option. In multi-select, adds to the selection. |
| Space | Select the focused option. In multi-select, toggles selection. |
| → | Open a submenu when a SubTrigger is focused and move focus to its first item. |
| ← | Close a submenu and return focus to its SubTrigger. |
| Esc | Close an open submenu and return focus to its SubTrigger. |
| A-Z/0-9 | Typeahead — jump to the next option whose label starts with the typed characters (case-insensitive, 500ms buffer). |
Accessibility
The Listbox component implements the WAI-ARIA Listbox pattern using aria-activedescendant:
Contentrenders asrole="listbox"withtabindex="0"andaria-activedescendanttracking the active option.Optionrenders asrole="option"witharia-selectedreflecting the selection state.aria-multiselectable="true"is applied whenselectionMode="multiple".Grouprenders asrole="group"and is labelled by itsGroupLabel.- DOM focus stays on the listbox container during keyboard navigation.
- Disabled options expose
aria-disabled="true"and cannot be selected.