- Docs
- Components
- Forms
Combobox
Pick from many by typing to filter: one value, or several as pills. It can ask a server.
- Import
- @qeetrix/react/experimental
- Status
- ExperimentalSince 0.0.6
- Renders
<input role="combobox">Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// Experimental: from the package's experimental entry, until it's stable.
import { Combobox } from "@qeetrix/react/experimental";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
items | ComboboxItem[] | ComboboxItemGroup[] | required | All flat, or all in groups: { value, label, description, disabled }. |
value · defaultValue · onValueChange | Value | Value[] | — | The chosen ID, or IDs with multiple. |
multiple | boolean | false | Several, as removable pills. |
placeholder | string | — | Shown while empty: an example. |
icon | IconSource | — | A leading icon, 16px. |
filter | (item, query) => boolean | null | label contains | How an option matches: its label, ignoring case and accents. null shows items as given; with onSearch it's null. |
allowCustom | boolean | false | Typed text that matches no option is offered ("Use …") and can be the value. String values, flat items. |
onSearch | (query: string) => void | — | Search the server when typing pauses; "" at once when cleared. |
searchDelay | number | 300 | The pause before onSearch, in ms. |
loading | boolean | false | Shows "Searching…", announced, and marks the list busy. |
messages | Partial<…combobox> | — | Its words, over QeetrixProvider's. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
combobox | <div> | The field's box. |
combobox-input | <input> | The input; ref lands here, and a Field labels it. |
combobox-chips | <div> | The pills, with multiple; each combobox-chip has combobox-chip-remove. |
combobox-clear | <button> | Clear: only while there's a value; named after the field. |
combobox-popup | <div> | The list: combobox-list, its combobox-group and combobox-option. |
combobox-status | <div role="status"> | "Searching…" or "No matches". |
04
A directory on the server
onSearch and loading; the server's results show as given, and a chosen value keeps its label when they leave it out.
const [query, setQuery] = useState("");
const { data, isFetching } = useQuery({ queryKey: ["people", query], queryFn: () => searchPeople(query) });
<Field label="Owner">
<Combobox items={data ?? []} onSearch={setQuery} loading={isFetching} />
</Field>