Getting started

Actions

Forms

Layout

Navigation

Overlays

Feedback

Data display

Controllers

Helpers

Recipes

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

Cat
Dog
No results found.

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.

CatDog
Cat
Dog
No results found.
<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:

ValueOpens when
input (default)The user types a matching query, or uses the trigger / arrow keys
focusThe input receives focus (and while typing)
manualThe trigger button or arrow keys only; typing filters without opening
Cat
Dog
No results found.

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.

PartCSS roles
Control row (rui-combobox__control)border, background, radius-control; focus-ring on focus-within
Input texton-background, --text-control, --space-control-*
Disabledopacity-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

AttributeTypeDefaultDescription
valuestringomittedComma-separated selected tokens. Empty selection removes the attribute. The JS property is string[].
namestring''Submission name, with one FormData entry per selected value, and the key a surrounding RuiField registers the control under.
labelstring''Accessible name when there is no visible RuiLabel.
placeholderstring''Placeholder text for the input.
requiredbooleanfalseRequire at least one selected value.
requiredMessagestring'Select at least one option.'Validation message of an empty required selection. Attribute: required-message.
disabledbooleanfalseDisable the input and trigger.
selection-modesingle · multiplesingleSingle or multi-select.
should-close-on-selectbooleanWhether selection closes the popup (defaults to true for single, false for multiple).
trigger-kindinput · focus · manualinputControls what opens the listbox.
portalbooleanfalseRender 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-containerstringCSS 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

TargetRequiredHost writesAuthor owns
[data-ref="root"]yes—shell for popover anchoring
[data-combobox-input]yesrole, aria-expanded, aria-controls, id, disabledthe input
[data-combobox-listbox]yeshiddenpopup shell
[role="option"]yes (in listbox)aria-selecteddata-value, label text
[data-combobox-trigger]noaria-expanded, tabIndex="-1"toggle button
[data-combobox-clear]nohidden, disabledclear 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

EventDetailDescription
inputnoneFired when an option is selected, a chip is removed, clear runs, or Escape clears a closed field, after value is updated.
changenoneFired 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

ComponentTarget stampedNotes
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

ClassDescription
.rui-comboboxRoot surface.
.rui-combobox__controlBordered control-height row.
.rui-combobox__inputCombobox text input.
.rui-combobox__valueSelected-value chip region.
.rui-combobox__listboxPopup shell (adds rui-popover rui-popover--listbox rui-floating).

Theme roles

PartCSS 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" with aria-expanded reflecting popup state.
  • Multiple mode marks the popup listbox aria-multiselectable="true"; each known option toggles aria-selected.
  • Compose RuiComboboxClear for an explicit clear action; it restores focus to the input.
  • Associate a visible label via RuiLabel or label.