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.

Preview

No preview output yet.

live.tsxReady

Max visible items

Listbox with a fixed-height scroll region for a long option list.

Preview

No preview output yet.

live.tsxReady

Single selection with submenu

Grouped options with a nested submenu and controlled selection.

Preview

No preview output yet.

live.tsxReady

Multiple selection with submenu

Multi-select listbox with nested options and a live selection readout.

Preview

No preview output yet.

live.tsxReady

Anatomy

tsx
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.

PropTypeDefault
asChild
booleanfalse
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.

PropTypeDefault
asChild
booleanfalse

Content

Focusable listbox surface owning live option registration and keyboard navigation.

PropTypeDefault
asChild
booleanfalse
AttributeValues
rolelistbox
aria-labelledbyEffective Label ID, when present
aria-multiselectabletrue | false
aria-activedescendantID of the active connected option

Viewport

Optional non-roled native overflow box inside Content.

PropTypeDefault
asChild
booleanfalse
maxVisibleItems*
number—
AttributeValues
[data-listbox-viewport]Empty attribute

Option

Selectable div option; registration follows the current physical host and DOM order.

PropTypeDefault
asChild
booleanfalse
value*
string—
disabled
booleanfalse
AttributeValues
roleoption
aria-selectedtrue | false
aria-disabledtrue when disabled
[data-active]true | false

Group

Div group named by the current GroupLabel host.

PropTypeDefault
asChild
booleanfalse
AttributeValues
rolegroup
aria-labelledbyEffective GroupLabel ID, when present

GroupLabel

Div label whose live ID names its group.

PropTypeDefault
asChild
booleanfalse

Sub

State-only submenu provider. Renders no DOM and has no asChild prop.

PropTypeDefault
offset
{ x: number; y: number }{ x: 0, y: 0 }

SubTrigger

Div option that opens a submenu with click, hover, ArrowRight, Enter or Space.

PropTypeDefault
asChild
booleanfalse
disabled
booleanfalse
AttributeValues
roleoption
aria-expandedtrue | false
aria-haspopuplistbox
[data-active]true | false

SubContent

Portalled submenu collection; mounts only while the submenu is open.

PropTypeDefault
asChild
booleanfalse
AttributeValues
rolelistbox
aria-labelledbyEffective SubTrigger ID
aria-activedescendantID of the active connected option

Keyboard

ShortcutAction
↓Move focus to the next option. Wraps to first.
↑Move focus to the previous option. Wraps to last.
HomeMove focus to the first option.
EndMove focus to the last option.
EnterSelect the focused option. In multi-select, adds to the selection.
SpaceSelect 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.
EscClose an open submenu and return focus to its SubTrigger.
A-Z/0-9Typeahead — 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:

  • Content renders as role="listbox" with tabindex="0" and aria-activedescendant tracking the active option.
  • Option renders as role="option" with aria-selected reflecting the selection state.
  • aria-multiselectable="true" is applied when selectionMode="multiple".
  • Group renders as role="group" and is labelled by its GroupLabel.
  • DOM focus stays on the listbox container during keyboard navigation.
  • Disabled options expose aria-disabled="true" and cannot be selected.
Previous
Label