A text field that filters a list of options as you type, following the WAI-ARIA combobox pattern. It picks one value, several values shown as removable chips, or text that matches no option. The list opens in the top layer and sits under the field through CSS anchor positioning, so overflow: hidden on a parent does not cut it. With a name, the value goes into the form through hidden inputs. The icons are inline SVG, there are no dependencies besides React.
Browser Support
Limited availability4 featuresDetails
Places the list under the field and flips it up when there is no room below. Without it the list is a plain block under the field, inside the page flow.
Puts the list in the top layer, above dialogs and clipped containers. Used together with anchor positioning only.
Fades the list in when it opens. Without it the list appears at once.
Fades the list out when it closes. Without it the list disappears at once.
Preview
Value: next. Type “st” or “re”, then ArrowDown, Home/End, Enter, Escape.
Installation
Usage
"use client"
import * as React from "react"
import { Combobox } from "@/components/ui/combobox"
const frameworks = [
{ value: "next", label: "Next.js", description: "React, full-stack" },
{ value: "astro", label: "Astro", description: "Content sites, islands" },
{ value: "nuxt", label: "Nuxt", description: "Vue, full-stack" },
]
export function FrameworkPicker() {
const [value, setValue] = React.useState("next")
return (
<Combobox
options={frameworks}
value={value}
onValueChange={setValue}
placeholder="Search frameworks…"
inputProps={{ "aria-label": "Framework" }}
/>
)
}Examples
Several values, custom values, form
multiple shows the picked values as chips and keeps the list open after a pick. allowCustomValue adds an “Add” row for text that matches nothing. Options come from ComboboxOption children here, and name sends one hidden input per value.
<form action={saveLabels}>
<Combobox
multiple
name="tags"
allowCustomValue
defaultValue={["bug", "needs-triage"]}
placeholder="Add labels…"
>
<ComboboxOption value="bug" description="Something isn't working">bug</ComboboxOption>
<ComboboxOption value="docs" description="Improvements to documentation">documentation</ComboboxOption>
<ComboboxOption value="needs-triage">needs triage</ComboboxOption>
<ComboboxOption value="wontfix" disabled>wontfix</ComboboxOption>
</Combobox>
<Button type="submit">Save labels</Button>
</form>Search on the server
filter={false} shows options exactly as you pass them. Control the typed text with inputValue and onInputValueChange, fetch results and show loading while the request runs.
Results arrive after a simulated 600 ms request. Value: none
const [text, setText] = React.useState("")
const [value, setValue] = React.useState("")
const { results, loading } = useCitySearch(text) // your fetch with debounce
<Combobox
options={results}
filter={false}
loading={loading}
loadingMessage="Searching cities…"
emptyMessage={text ? "No city found" : "Type to search"}
inputValue={text}
onInputValueChange={setText}
value={value}
onValueChange={setValue}
/>Your own texts
All visible and announced texts are props. The functions have to come from a client component, as in this page’s demos.
<Combobox
options={options}
emptyMessage="Ничего не найдено"
loadingMessage="Загрузка…"
addMessage={(query) => <>Добавить «{query}»</>}
resultsMessage={(count) => `Найдено: ${count}`}
removeLabel={(label) => `Удалить ${label}`}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| options | ComboboxOptionData[] | - | Options as data. Ignored when ComboboxOption children are given |
| children | ComboboxOption[] | - | ComboboxOption elements, for custom content in a row |
| multiple | boolean | false | Pick several values, shown as removable chips |
| value | string | string[] | - | Selected value (controlled): a string, or an array with multiple |
| defaultValue | string | string[] | - | Initial value when uncontrolled |
| onValueChange | (value: string | string[]) => void | - | Called with the new value or array of values |
| name | string | - | Form field name. The value goes into hidden inputs |
| placeholder | string | - | Placeholder of the input |
| disabled | boolean | false | Disables the field |
| required | boolean | false | The form will not submit while nothing is picked |
| allowCustomValue | boolean | false | Accept text that matches no option (Enter or the Add row) |
| inputValue | string | - | Typed text (controlled) |
| onInputValueChange | (text: string) => void | - | Called on every keystroke |
| filter | boolean | (option, query) => boolean | true | Built-in filter by words of the label, your own function, or false for server-side search |
| loading | boolean | false | Show a loading row instead of results |
| loadingMessage | ReactNode | "Loading…" | Text of the loading row |
| emptyMessage | ReactNode | "No results" | Text when nothing matches |
| addMessage | (query: string) => ReactNode | Add “…” | Content of the Add row |
| resultsMessage | (count: number) => string | "N results" | Result count for screen readers |
| removeLabel | (label: string) => string | "Remove …" | Accessible name of the chip remove button |
| inputProps | ComponentProps<"input"> | - | Props for the inner <input>: id, aria-label, autoFocus… |
Components
| Component | Description |
|---|---|
| Combobox | The field, chips, hidden inputs and the list |
| ComboboxOption | Declarative option: value, label, description, disabled. Children replace the label in the list |
Features
- Keyboard: arrows, Home/End, Enter, Escape clears the field, Backspace removes the last chip; focus stays in the input
- Screen readers: role combobox with aria-activedescendant, a listbox and a polite count of results
- Highlighted matches: typed words are marked in every option label
- Native forms: hidden inputs with name, required while empty, reset through your own state
- No positioning script: anchor positioning in CSS; older browsers get a block under the field
- Reduced motion: the list opens without the fade and slide