Components · Form Controls
Combobox Field
A labelled, searchable single choice that looks like a Select. For lists longer than about ten options.
import { ComboboxField } from '@nexub/react';Usage
One choice from a long list: people, countries, companies, codes.
A list the server searches (`onSearch` with `loading`).
Ten options or fewer: use Select.
Several choices: use MultiSelect.
Free text with suggestions: use Autocomplete.
Playground
Props
Where the company is registered
<ComboboxField label="Country" description="Where the company is registered" options={countries} value={value} onValueChange={setValue} />Examples
Default
Groups and a none option
Server search
States
Where the company is registered
defaultWhere the company is registered
disabledWhere the company is registered
invalidWhere the company is registered
readOnlyWhere the company is registered
loadingWhere the company is registered
size="sm"Where the company is registered
size="md"Where the company is registered
size="lg"
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| labelrequired | React.ReactNode | — | The field label. ComboboxPicker is the same control without it (name it with aria-label). |
| optionsrequired | ComboboxOption[] | — | { value, label, description?, keywords?, disabled?, group? }. description is a second line; keywords and description are searched too; group lists the option under a heading. |
| value | string | — | The picked value, null for none. |
| defaultValue | string | null | The picked value, null for none. |
| onValueChange | ((value: string) => void) | — | Called with the picked value, or null from the none option. |
| noneOption | string | — | A first option that clears the value, e.g. "No manager". |
| onSearch | ((text: string) => void) | — | Server search: the list is not filtered here while onSearch is set. |
| loading | boolean | — | Server search: the list is not filtered here while onSearch is set. |
| selectedOption | ComboboxOption | — | Labels the value when it is not in options (before an async search has run). |
| description | React.ReactNode | — | Help and the inline error under the field. error marks it invalid. |
| error | React.ReactNode | — | Help and the inline error under the field. error marks it invalid. |
| name | string | — | A hidden input posts the value with a plain form. Inside Form, also picks up the form error. |
| size | 'sm' | 'md' | 'lg' | 'md' | Height of the field. |
| sheet | false | true | 'auto' | 'auto' (a bottom sheet below 768px) | The list as a bottom sheet below 768px. |
| aria-describedby | string | — | |
| aria-invalid | false | true | 'true' | 'false' | — | |
| aria-label | string | — | |
| aria-required | false | true | 'true' | 'false' | — | |
| className | string | — | |
| disabled | boolean | — | |
| emptyText | React.ReactNode | 'No results found.' | Shown when the search finds nothing. |
| id | string | — | |
| invalid | boolean | — | |
| placeholder | string | 'Select…' | Shown when nothing is picked. |
| readOnly | boolean | — | Shows the value; the list can't open. Stays focusable. |
| required | boolean | — | |
| searchPlaceholder | string | 'Search…' | The search box's placeholder. |
Accessibility
Keyboard
- Enter / Space / Arrow Down
Opens the list with focus in the search box.
- Arrow Up / Arrow Down
Moves through the options.
- Enter
Picks the highlighted option and closes.
- Escape
Closes without changing the value.
Notes
The trigger is a `combobox` named by the label; the picked option is its text.
Description and error are linked with `aria-describedby`.