Listbox
Listboxes present a scrollable set of options with single or multiple selection. Standalone, they are an inline chooser. Inside select and combobox, they are the option surface of the popup, without a host of their own.
Try it
Mental model
<rui-listbox> is a behavior host: RuiListboxOption children stay in parent JSX. The custom element coordinates aria-selected, roving tabindex, and the input and change events. Inside a select or combobox popup the listbox is not this host: the parent renders only the [role="listbox"] surface and owns selection and keyboard.
The live value property is always a string[] ([] when nothing is selected). The HTML attribute is those tokens as a comma-separated string. JSX may pass a string or an array; a string is parsed as CSV. input and change fire on the host and carry no detail; read host.value. Commas in the attribute are delimiters.
A named standalone listbox submits one native FormData entry per selected value and follows disabled fieldsets. Use required to require a selection. A plain form reset restores the initial selection, and browser state restoration recovers the saved selection. A listbox inside a select or combobox popup is plain markup, so it is never listed in the form and does not follow a fieldset on its own.
Usage
Add RuiListboxOption children with unique value props, or pass options for the default composition.
import { RuiListbox, RuiListboxOption } from '@ecopages/radiant-ui/listbox';
<RuiListbox value="cat" label="Animal">
<RuiListboxOption value="cat">Cat</RuiListboxOption>
<RuiListboxOption value="dog">Dog</RuiListboxOption>
</RuiListbox><RuiListbox
value="cat"
label="Animal"
options={[
{ value: 'cat', label: 'Cat' },
{ value: 'dog', label: 'Dog' },
]}
/>Custom markup
<rui-listbox> coordinates any light-DOM tree that matches its query contract. The Rui* helpers stamp these targets; they are not required.
import '@ecopages/radiant-ui/listbox';
<rui-listbox value="cat" label="Animal">
<div role="listbox" class="rui-listbox rui-listbox--bordered">
<div role="option" data-value="cat" class="rui-listbox__option">Cat</div>
<div role="option" data-value="dog" class="rui-listbox__option">Dog</div>
</div>
</rui-listbox>BEM classes are presentation-only. Do not set aria-selected or tabIndex on options — the host owns those.
Embedded listboxes
Set embedded on the RuiListbox view when the listbox lives inside a select or combobox popup. The view then stamps only the [role="listbox"] surface, without the <rui-listbox> host, so nothing form-associated sits inside the parent: the parent owns selection, keyboard and form state, and border chrome is omitted so the popup can provide it. name, required and the other host props do not apply, and the surface is not a field control: place the parent select or combobox inside RuiField. In raw markup, drop the rui-listbox wrapper and keep the [role="listbox"] div. bordered overrides the border default.
Selection indicators
The options API adds the default check SVG only in multiple mode. Single-select uses the selected-option background alone. For a composed option in either mode, place RuiListboxOptionIndicator as a child and pass children to replace the check. Visibility follows aria-selected; the indicator is decorative.
import { RuiListboxOption, RuiListboxOptionIndicator } from '@ecopages/radiant-ui/listbox';
import { RuiIconCheck } from '@ecopages/radiant-ui/icons';
<RuiListboxOption value="cat" label="Cat">
Cat
<RuiListboxOptionIndicator>
<RuiIconCheck />
</RuiListboxOptionIndicator>
</RuiListboxOption>Set label when the option contains decorative nodes (emoji, icons). Without it, the accessible name is the option's text minus the indicator subtree.
Multiple selection
selectionMode="multiple" exposes aria-multiselectable="true". Click or Space/Enter toggles the focused option. Arrow keys move focus without changing the selection. Shift+click, and Shift with an arrow key, Home or End, select the range from the last option you chose or toggled; Ctrl+A (Cmd+A on macOS) selects every enabled option.
<RuiListbox
selectionMode="multiple"
value={['apple', 'banana']}
label="Favorite fruit"
options={[
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
]}
/>Theming
Listbox surfaces map to semantic surface and selection roles, never Tailwind palette steps.
| Part | CSS roles |
|---|---|
List surface (rui-listbox) | background |
| Bordered variant | border, radius-container |
| Option | on-background, radius-control, space-control-* |
| Option hover | surface-container-low |
| Active option (visual focus) | surface-container, on-background |
| Selected option | primary, on-primary |
| Focus ring | focus-ring |
Set the listed semantic custom properties in your app's theme stylesheet, such as --primary and --on-primary for selected options. Embedded listboxes inherit the popup surface from the parent shell. Indicator layout uses :has([data-listbox-option-indicator]); there is no public CSS variable for the check glyph — replace it with helper children.
API
RuiListbox is a custom element (<rui-listbox>) around a role="listbox" surface. It is form-associated.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
value | string | omitted | Comma-separated selected tokens. Empty selection removes the attribute. The JS property is string[]. |
name | string | '' | Submission name of a standalone listbox, with one FormData entry per selected value, and the key a surrounding RuiField registers the control under. |
label | string | '' | Accessible name for the list. |
required | boolean | false | Require at least one selected value. |
requiredMessage | string | 'Select at least one option.' | Validation message of an empty required selection. Attribute: required-message. |
disabled | boolean | false | Disable all selection. |
selection-mode | single · multiple | single | Single or multiple selection. |
embedded | boolean | false | View prop, not an attribute: renders the surface without the host for a select or combobox popup. |
bordered | boolean | true, false when embedded | Override the border. |
Light-DOM contract
| Target | Required | Host writes | Author owns |
|---|---|---|---|
[role="listbox"] | yes | id, aria-multiselectable (multiple mode) | the list node |
[role="option"] | yes | aria-selected, roving tabIndex | data-value, data-label, aria-disabled, hidden |
data-value | per option | — | selection identity; fallback trimmed text |
data-label | per option | — | accessible name when children include decorative nodes |
Do not set aria-selected or tabIndex on options. Nested hosts: none.
Events
| Event | Detail | Description |
|---|---|---|
input | none | Fired when an option is selected, after value is updated. |
change | none | Fired right after input on the same interaction. |
Read the value from the control (host.value); the events carry no detail. Both fire on the host after value is updated, and a programmatic write (property, attribute, store, reset) dispatches nothing. Act only when event.target is the host: a nested part's events can reach a listener above the host.
View helpers
| Component | Target stamped | Notes |
|---|---|---|
RuiListbox | <rui-listbox> + [role="listbox"] shell, or the shell alone when embedded | Accepts options or children. |
RuiListboxOption | [role="option"], data-value, data-label | — |
RuiListboxOptionIndicator | [data-listbox-option-indicator] | Decorative; not queried by the host. |
CSS classes
| Class | Description |
|---|---|
.rui-listbox | Scrollable option list surface (role="listbox"). |
.rui-listbox--bordered | Bordered standalone listbox. |
.rui-listbox__option | Selectable list option (RuiListboxOption). |
.rui-listbox__option-indicator | Selected-state indicator inside an option. |
Theme roles
| Part | CSS variables consumed |
|---|---|
| List surface | --background |
| Bordered variant | --border, --radius-container |
| Option | --on-background, --radius-control, --space-control-x, --space-control-y |
| Option hover / active | --surface-container-low, --surface-container |
| Selected option | --primary, --on-primary |
| Focus ring | --focus-ring |
Accessibility
- Options expose
role="option"witharia-selectedfor the current choice. - Multiple mode exposes
aria-multiselectable="true". The visual indicator is decorative; selection remains onaria-selected. - Arrow keys move focus between options. In multiple mode they do not toggle; Space or Enter does. Shift with an arrow extends the selection, and Ctrl/Cmd+A selects all enabled options.
- Typing a character moves focus to the next option whose label starts with it, and characters typed quickly match a prefix. In single mode this selects the option, like the arrow keys.
- Provide a
labelor external heading so users know what the list represents.