A list of options on the page, for one value or several, with the APG's two selection models, ranges and select all, as a form control.
A list of options that stays on the page, for choosing one value or several (the APG
listbox pattern). It is a form control: it
submits, resets and validates, alone or in a Field. A list that pops up from a
button is a Select; a list filtered by a text input, a
Combobox or an Autocomplete.
Base UI has no Listbox: the APG decides the roles, the keys and the selection models; Select's
parts and names are the API pattern.
Focus on the options: DOM focus moves to the options (one tab stop, a roving tabindex).
Tab enters on the first selected option, else the first one; while the focus stays inside, the
tab stop is the focused option (data-highlighted).
The keys: the arrows along orientation (mirrored in RTL when horizontal), Home, End,
PageUp and PageDown (a page of the scroll container), and typeahead on the options' text.
loopFocus wraps at the ends.
Two selection models (selectionBehavior): "toggle", the APG's recommended one, never
selects on a move (Space and Enter select or toggle); "replace", the alternative one, makes the
selection follow the focus (Ctrl moves without selecting, Ctrl+Space toggles).
Ranges and select all (multiple): Shift with an arrow moves and toggles, Shift+Space
selects from the anchor (the last option toggled), Ctrl+Shift+Home / End select to an end,
Ctrl+A selects every option (or none, when they all are); Shift and a press select a range,
Ctrl and a press toggle (the replace model).
Disabled options take focus, never the selection; ranges and select all skip them.
The value is a string or null, or with multiple an array of strings in the list's order.
Forms: a visually hidden input carries the value and required (with multiple, one
hidden input per value). A form reset returns an uncontrolled list to defaultValue. In a
Field, the list is the field's control: named and described by it,
aria-invalid on the Root.
The collections mechanism: the list model, the selection rules and the key map are the
toolkit's /selection entry, which Menu, Tabs or Dialog never import.
Long and loaded lists: for thousands of items, or items loaded page by page, use
ListboxVirtual: ListboxVirtual.Root (/listbox-virtual) takes
every option as items and renders only the ones in view, with the same keys, typeahead, ranges
and select all over every item. Its pages can come from a loader through the async
list (loading, onLoadMore). It is opt-in: this entry ships no
virtualizer.
Every part also takes what the primitive contract gives:
render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which
it forwards. The names below are React's; Vue binds them the same way (v-model:value,
@value-change), and Angular as inputs and outputs ([(value)], (valueChangeDetails) with
{ value, details }).
role="listbox", aria-orientation, aria-multiselectable, aria-required, aria-disabled, data-orientation, data-multiple, data-disabled; in a Field, the field's states
Item
role="option", tabindex (0 on the tab stop), aria-selected ("true" or "false"), aria-disabled, data-selected, data-highlighted (the focused option), data-disabled
ItemIndicator
aria-hidden="true"
Group
role="group", aria-labelledby
Separator
role="presentation", data-orientation (across the list)