Skip to content
EspañolEnglish
All components (204)

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.

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.
defaultInputValuestring—
defaultSelectedKeystring | nullThe key chosen at the start, without controlling it from outside.
disabledboolean—
errorstring—
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.
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.
onInputChange(text: string) => void—
onOpenChange(open: boolean) => voidWhen the list opens or closes.
onSelectionChange(key: string | null) => void—
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—
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 ui.amset.tech: