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) orTagsInput(without a list).
Keyboard and accessibility: those of SearchField (the ARIA combobox pattern).
What it looks like
If it's not in the list, type it in
Madrid
Barcelona
Valencia
Seville
Type “ma” and the list filters.
Anything you type that is not in the list is discarded on leaving
Madrid
Barcelona
Valencia
Seville
<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.
| Prop | Type | What it does |
|---|---|---|
labelrequired | string | — |
optionsrequired | readonly ListOption[] | — |
allowsCustomValue | boolean | With `false` only an option from the list is valid: whatever is typed that does not match is discarded on leaving. `true` by default. |
autoFocus | boolean | — |
className | string | Merged with the library classes; it does not replace them. |
clearable | boolean | A 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. |
clearLabel | string | What the screen reader says on the clear button. By default, “Clear search”. |
defaultInputValue | string | — |
defaultOpen | boolean | The list open at the start, without controlling it from outside. |
defaultSelectedKey | string | null | The key chosen at the start, without controlling it from outside. |
disabled | boolean | — |
error | string | — |
filter | TextMatch | How 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. |
hiddenLabel | boolean | The 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. |
highlightMatches | boolean | Highlights 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. |
hint | string | — |
inputValue | string | The typed text, controlled from outside. |
invalid | boolean | — |
loading | boolean | The 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. |
loadingText | string | What 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. |
name | string | So that the chosen key travels in a native form. |
noResultsMessage | string | Text when what is typed finds nothing. |
offset | number | Separation in pixels between the field and the list. By default, none. |
onBlur | () => void | On leaving the field. The form uses it to mark that it has been touched. |
onClear | () => void | Called when the field is emptied with the button, after `onInputChange('')` and `onSelectionChange(null)`. |
onInputChange | (text: string) => void | — |
onOpenChange | (open: boolean) => void | When the list opens or closes. |
onSelectionChange | (key: string | null) => void | — |
onSubmit | (text: string, details: SearchSubmitDetails) => void | Enter 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. |
open | boolean | The list open, controlled from outside. Goes with `onOpenChange`, which reports what the field WANTS to do. |
placeholder | string | — |
placement | Placement | Where the list appears. By default, right below the field. |
readOnly | boolean | — |
renderOption | OptionRender<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`. |
required | boolean | — |
searchButton | string | boolean | A 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"). |
searchLabel | string | The name of the magnifier button for the screen reader. Defaults to "Search". |
selectedKey | string | null | The chosen key, controlled from outside. |
serverFiltered | boolean | The 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" | — |
variant | FieldVariant | — |
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:
