Combobox
A combobox combines a text field with a filterable popup list. Use it when users need to search a known set of options. Typed text filters the list; only selecting an option commits a value.
Try it
Mental model
<rui-combobox> is a behavior host: helpers place the input row and popup; the custom element owns filtering, keyboard, and selection. Options live in an embedded RuiListbox (a [role="listbox"] without a host), usually wrapped in RuiAutocomplete. Named regions are Composition Helpers, not HTML slots.
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.
Tab with an active option in a single combobox picks that option and moves focus on. In selection-mode="multiple" Tab only closes the popup and leaves the selection as it is; Enter or a click toggles an option.
Important: typing does not create a custom value. Enter with no active option closes the popup. Escape while closed clears the committed value and the input. If only predefined options are valid, that is already the runtime contract — do not expect free-text to be stored on value.
A named combobox 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. The submitted values come from the selection. The filter textbox is unnamed.
Usage
Pass options for the default composition, or compose the helpers explicitly. Always set embedded on the listbox inside the popup. The view then renders the [role="listbox"] surface without a <rui-listbox> host, so the combobox owns selection, keyboard and form state.
import {
RuiCombobox,
RuiComboboxClear,
RuiComboboxControl,
RuiComboboxInput,
RuiComboboxListbox,
RuiComboboxTrigger,
} from '@ecopages/radiant-ui/combobox';
import { RuiAutocomplete, RuiAutocompleteCollection, RuiAutocompleteEmpty } from '@ecopages/radiant-ui/autocomplete';
import { RuiListbox, RuiListboxOption } from '@ecopages/radiant-ui/listbox';
import { RuiIconX } from '@ecopages/radiant-ui/icons';
<RuiCombobox value="cat" placeholder="Choose an animal">
<RuiComboboxControl>
<RuiComboboxInput />
<RuiComboboxClear aria-label="Clear animal selection">
<RuiIconX />
</RuiComboboxClear>
<RuiComboboxTrigger />
</RuiComboboxControl>
<RuiComboboxListbox>
<RuiAutocomplete>
<RuiAutocompleteCollection>
<RuiListbox embedded>
<RuiListboxOption value="cat">Cat</RuiListboxOption>
<RuiListboxOption value="dog">Dog</RuiListboxOption>
</RuiListbox>
<RuiAutocompleteEmpty>No results found.</RuiAutocompleteEmpty>
</RuiAutocompleteCollection>
</RuiAutocomplete>
</RuiComboboxListbox>
</RuiCombobox>Children on RuiComboboxClear and RuiComboboxTrigger replace the default SVGs. For decorated options, set label on RuiListboxOption so the committed input text stays clean of icons and indicators.
Custom markup
<rui-combobox> coordinates any light-DOM tree that matches its query contract. The Rui* helpers stamp these targets; they are not required.
import '@ecopages/radiant-ui/combobox';
<rui-combobox value="cat" placeholder="Choose an animal">
<div data-ref="root" class="rui-combobox">
<div class="rui-combobox__control">
<input type="text" data-combobox-input data-autocomplete-input />
<button type="button" data-combobox-trigger></button>
</div>
<div data-combobox-listbox hidden>
<div role="listbox">
<div role="option" data-value="cat">Cat</div>
</div>
</div>
</div>
</rui-combobox>Multiple selection
selectionMode="multiple" toggles known options and keeps the popup open. Selected options render as removable chips. Typed text only filters; it is not appended as a token.
<RuiCombobox
selectionMode="multiple"
value={['ca', 'ny']}
options={[
{ value: 'ca', label: 'California' },
{ value: 'ny', label: 'New York' },
]}
/>For composed layouts, place RuiComboboxValue (with a RuiTagGroup) before RuiComboboxInput. Add RuiListboxOptionIndicator inside an option to replace the selected checkmark.
Trigger kind
triggerKind controls what opens the listbox:
| Value | Opens when |
|---|---|
input (default) | The user types a matching query, or uses the trigger / arrow keys |
focus | The input receives focus (and while typing) |
manual | The trigger button or arrow keys only; typing filters without opening |
Lazy script
When the script loads after the page, for example on first interaction, the element keeps the input and the text the visitor typed. It applies the filter for that text and, when the input has focus, an option matches and triggerKind is not manual, opens the listbox. In single mode a selected value still replaces the text with its label.
Suggestions that load later
A typeahead renders its options after the input event that opens the listbox. When typing left a query with nothing to show, options added to the popup open the listbox once one of them matches the typed text, while the input has focus and unless triggerKind is manual. The filter runs again for every option that arrives. A list the visitor selected from or dismissed with Escape stays closed, and a list that is cleared and refilled does not close in between. Add late options to the existing listbox: options in a replaced popup are not observed.
Portal
By default the popup renders next to the trigger, so it is clipped by an overflow: hidden ancestor and can be painted over by later content. Set portal to render it in document.body while it is open, and portal-container (a CSS selector, resolved each time the popup opens) to render it in another element. The portalContainer property also takes an element or a function that returns one, and can change between opens.
The popup returns to its place when it closes. Tab order follows the popup's position in the document while it is open, so a portaled popup is best reached with the arrow keys; selection, labels and aria-controls work as without portal.
Theming
Combobox surfaces map to semantic surface roles, never Tailwind palette steps. Override at the theme layer.
| Part | CSS roles |
|---|---|
Control row (rui-combobox__control) | border, background, radius-control; focus-ring on focus-within |
| Input text | on-background, --text-control, --space-control-* |
| Disabled | opacity-muted |
Popup (rui-combobox__listbox) | popover surface + shadow-overlay (via rui-popover) |
Icon swaps are Composition Helper children, not CSS variables.
API
RuiCombobox is a custom element (<rui-combobox>) that coordinates a composed input row and listbox popup. It is form-associated; the filter textbox is not a form value.
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, with one FormData entry per selected value, and the key a surrounding RuiField registers the control under. |
label | string | '' | Accessible name when there is no visible RuiLabel. |
placeholder | string | '' | Placeholder text for the input. |
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 the input and trigger. |
selection-mode | single · multiple | single | Single or multi-select. |
should-close-on-select | boolean | Whether selection closes the popup (defaults to true for single, false for multiple). | |
trigger-kind | input · focus · manual | input | Controls what opens the listbox. |
portal | boolean | false | Render the popup in document.body, or in portal-container, while it is open, so a clipped or overflow: hidden ancestor cannot cut it off. |
portal-container | string | CSS selector of the element a portaled popup goes to instead of document.body, resolved each time it opens. The portalContainer property also takes an element or a function that returns one. |
Light-DOM contract
| Target | Required | Host writes | Author owns |
|---|---|---|---|
[data-ref="root"] | yes | — | shell for popover anchoring |
[data-combobox-input] | yes | role, aria-expanded, aria-controls, id, disabled | the input |
[data-combobox-listbox] | yes | hidden | popup shell |
[role="option"] | yes (in listbox) | aria-selected | data-value, label text |
[data-combobox-trigger] | no | aria-expanded, tabIndex="-1" | toggle button |
[data-combobox-clear] | no | hidden, disabled | clear button |
[data-combobox-value] | no | — | chip region before input |
Nested hosts: optional rui-autocomplete. The listbox and the chips in [data-combobox-value] (a [data-tag-group], painted and removed by the combobox) are plain markup, so neither joins the form.
Events
| Event | Detail | Description |
|---|---|---|
input | none | Fired when an option is selected, a chip is removed, clear runs, or Escape clears a closed field, 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. The query input's own events reach listeners above the host too, so check the target.
View helpers
| Component | Target stamped | Notes |
|---|---|---|
RuiCombobox | <rui-combobox> + [data-ref="root"] | Accepts options or children |
RuiComboboxControl | — | Input row wrapper |
RuiComboboxInput | [data-combobox-input] | Also [data-autocomplete-input] |
RuiComboboxClear | [data-combobox-clear] | Hidden when empty |
RuiComboboxTrigger | [data-combobox-trigger] | Children replace chevron |
RuiComboboxValue | [data-combobox-value] | Before input in multiple mode |
RuiComboboxListbox | [data-combobox-listbox] | Place an embedded RuiListbox inside |
CSS classes
| Class | Description |
|---|---|
.rui-combobox | Root surface. |
.rui-combobox__control | Bordered control-height row. |
.rui-combobox__input | Combobox text input. |
.rui-combobox__value | Selected-value chip region. |
.rui-combobox__listbox | Popup shell (adds rui-popover rui-popover--listbox rui-floating). |
Theme roles
| Part | CSS variables consumed |
|---|---|
| Control row | --border, --background, --radius-control, --focus-ring |
| Input text | --on-background, --text-control, --space-control-x, --space-control-y |
| Disabled | --opacity-muted |
| Popup | --shadow-overlay (via rui-popover) |
Accessibility
- The input exposes
role="combobox"witharia-expandedreflecting popup state. - Multiple mode marks the popup listbox
aria-multiselectable="true"; each known option togglesaria-selected. - Compose
RuiComboboxClearfor an explicit clear action; it restores focus to the input. - Associate a visible label via
RuiLabelorlabel.