Skip to content

Combobox

import { Combobox } from 'yarcl';

One component covers three modes.

The default. Typing filters the options; the value must be one of them. On blur, the text resets to the selected option’s label.

Value: none

<Combobox options={countries} value={country} onValueChange={setCountry} placeholder="Search countries" />

allowCustomValue accepts any text; the options are suggestions.

Value: none

<Combobox options={frameworks} allowCustomValue onValueChange={setValue} />

Filter on the server: set filter={false}, update options from onInputValueChange, and show loading in between.

Results arrive after 500 ms.

<Combobox
options={results}
filter={false}
loading={loading}
onInputValueChange={setQuery}
emptyMessage="No countries found"
/>
Key Action
typing filters and opens the list, highlighting the first match
moves the highlight (focus stays in the input)
Enter chooses the highlighted option
Esc closes the list

The input has role="combobox" and points at the highlighted option with aria-activedescendant.

Accepts every native <input> attribute except color, size, value, defaultValue and onChange.

PropTypeDefaultDescription
options requiredreadonly SelectOption<V>[]The options to suggest. For async search, update this as results arrive and set filter={false}.
allowCustomValuebooleanfalseAccepts typed text that doesn't match an option (typeahead / autocomplete). When false, the input resets to the selected option's label on blur.
colorColorconfigconfig.defaults.colorSemantic color, from the colors config.
defaultValueV | nullnullInitial selected value when uncontrolled.
emptyMessageReactNode'No results'Shown when no options match.
filterboolean | (option: SelectOption<V>, text: string) => booleantrueHow options are matched against the typed text. true: case-insensitive "contains" on the label; a function for custom matching; false to show options as given (e.g. already filtered by a server).
inputValuestringControlled text in the input.
loadingbooleanShows a loading row instead of options.
loadingMessageReactNode'Loading…'Shown while loading is set.
onInputValueChange(text: string) => voidCalled on every keystroke with the input text. Use it to fetch options for async search.
onValueChange(value: V | null) => voidCalled when an option is chosen, or with the typed text when allowCustomValue is set.
radius'size' | Radiusconfigconfig.defaults.radiusBorder radius, from the radii config, or 'size' for the radius named like the control's size.
sizeSizeconfigconfig.defaults.sizeControl size, from the sizes config.
valueV | nullControlled selected value. null means nothing is selected.