Skip to content
EspañolEnglish
All components (283)

Combobox

Fields · Combobox

What it is and when to use it

A field with a list of suggestions that also accepts free text: you type, the list filters, and you can pick an option or leave what you typed as it is. It is SearchField with allowsCustomValue switched on by default.

When to use it

  • A city, a category, a customer: there are suggestions, but anything else is valid too.
  • allowsCustomValue={false} turns it into a closed choice.
  • With thousands of options (over 300) it paints only the ones in view, also with groups, descriptions or custom rendering: each row can measure its own height and the scroll measures the same as if it were painted in full.

When not to

  • Several at once: MultiSelect (from a list) or TagsInput (without a list).

Keyboard and accessibility: those of SearchField (the ARIA combobox pattern).

What it looks like

Type “ma” and the list filters.

<Combobox label="Delivery city" options={ciudades} hint="If it's not in the list, type it in" inputValue={texto} onInputChange={setTexto} />
<Combobox
  label="Only those in the list"
  options={ciudades}
  allowsCustomValue={false}
  hint="Anything you type that is not in the list is discarded on leaving"
/>

Props

Import it with import { Combobox } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
labelrequiredstring—
optionsrequiredreadonly ListOption[]—
allowsCustomValuebooleanWith `false` only an option from the list is valid: whatever is typed that does not match is discarded on leaving. `true` by default.
autoFocusboolean—
classNamestringMerged with the library classes; it does not replace them.
clearablebooleanA button to empty the field, shown as soon as something is typed. It also clears the chosen option and puts the focus back in the input.
clearLabelstringWhat the screen reader says on the clear button. By default, “Clear search”.
defaultInputValuestring—
defaultOpenbooleanThe list open at the start, without controlling it from outside.
defaultSelectedKeystring | nullThe key chosen at the start, without controlling it from outside.
disabledboolean—
errorstring—
filterTextMatchHow the typed text matches each option: `contains` (the default), `startsWith`, `endsWith` or `fuzzy` (letters in order with gaps: “nvcl” finds “Nuevo cliente”), always ignoring accents and case. Or your own function, which gets the label and the typed text as they are.
hiddenLabelbooleanThe label for the screen reader only. For when the field sits inside something that already explains itself (a table cell, a group of filters), never to save space.
highlightMatchesbooleanHighlights in each option what matches the typed text, with the same criterion as `filter` (accent- and case-insensitive; with `fuzzy`, letter by letter). With a custom filter function it is not known what matches, so nothing is highlighted. With `renderOption`, the custom rendering wins.
hintstring—
inputValuestringThe typed text, controlled from outside.
invalidboolean—
loadingbooleanThe options are arriving. Marks the field as busy, shows a ring and a `loadingText` row in the list; the options that were already there stay.
loadingTextstringWhat the loading row says. "Loading…" by default.
menuTrigger"input" | "focus" | "manual"What opens the list: `input` (the default) when typing, `focus` as soon as the field receives focus, and `manual` only with the button or the arrows.
namestringSo that the chosen key travels in a native form.
noResultsMessagestringText when what is typed finds nothing.
offsetnumberSeparation in pixels between the field and the list. By default, none.
onBlur() => voidOn leaving the field. The form uses it to mark that it has been touched.
onClear() => voidCalled when the field is emptied with the button, after `onInputChange('')` and `onSelectionChange(null)`.
onInputChange(text: string) => void—
onOpenChange(open: boolean) => voidWhen the list opens or closes.
onSelectionChange(key: string | null) => void—
onSubmit(text: string, details: SearchSubmitDetails) => voidEnter with no option highlighted: search for the typed text as is (a shop's results page). With an option highlighted, Enter picks it and this is not called. It does not stop the surrounding form from submitting.
openbooleanThe list open, controlled from outside. Goes with `onOpenChange`, which reports what the field WANTS to do.
placeholderstring—
placementPlacementWhere the list appears. By default, right below the field.
readOnlyboolean—
renderOptionOptionRender<ListOption>Paints the inside of each option in the list: an avatar, two lines, a price. The name the screen reader reads is still `label`.
requiredboolean—
searchButtonstring | booleanA search button attached at the end of the field, which calls `onSubmit` with the typed text. `true` draws the magnifier (with `searchLabel` as its name) and a text draws a button with that text ("Search").
searchLabelstringThe name of the magnifier button for the screen reader. Defaults to "Search".
selectedKeystring | nullThe chosen key, controlled from outside.
serverFilteredbooleanThe list already comes filtered from outside (server-side search). By default the component itself filters with what is typed.
size"sm" | "md" | "lg"—
validationBehavior"aria" | "native"—
variantFieldVariant—

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: