Combobox
A searchable single choice: a trigger that opens a list with a search field, for long or server-loaded lists.
Select the field, type to filter and press Enter to choose. Type a term with no match to see the empty state.
When to use
- To pick one value from a list that is too long to scan: customers, templates, models, process numbers.
- When options come from a server and the search must call it (
ControlledInputCombobox). - When each option needs a short description to be told apart.
- Inside react-hook-form forms (
FormCombobox).
When not to use
- Short, fixed lists. Use Select.
- A value that may be missing from the list. Use Creatable combobox.
- A text field that suggests values while the user types. Use Autocomplete.
- Running commands or jumping between pages. Use Command.
- Several values at once. Use a multi-select.
Which one to use
| Component | The user | Options | Value | Typical use |
|---|---|---|---|---|
| Select | Picks from a list | Fixed, short | One of the options | Status, type, role |
| Combobox | Searches, then picks | Long or loaded from an API | One of the options | Customer, template, model |
| Creatable combobox | Searches, picks or types | Suggestions | An option or free text | Field name, tag |
| Autocomplete | Types and gets suggestions | Filtered as they type | One option, shown as a chip | Search for a person or entity |
| Command | Types to find an action | Actions and pages | Runs an action, holds no value | Global search, shortcuts |
Variants
The file exports four components over the same trigger and list.
| Component | Use for |
|---|---|
ControlledCombobox |
The default. You own value and setValue. |
Combobox |
Quick uncontrolled use with defaultValue and an optional onChange. |
ControlledInputCombobox |
You own the search text too, to filter or fetch results yourself. Adds loading, listFooter and shouldFilter. |
FormCombobox |
Wires a field of a react-hook-form form, with label, description and error message. |
States
Escolha um cliente para continuar.
There is no variant prop. Show an error with aria-invalid and a message linked by aria-describedby. In a form, FormCombobox does both.
Examples
With descriptions
Add description to an option when the label alone does not tell options apart. The selected option shows its description under the label in the trigger; use hideTriggerDescription to keep the trigger on one line.
Optional value
acceptEmpty adds a first option, labelled with the placeholder, that clears the choice. The cleared value is the string -.
Action pinned at the top
fixedOptions pins actions above the options, for example to create an item. Choosing one runs its action and closes the list; it does not change the value.
Search on the server
Own the search text, set shouldFilter={false} and pass already filtered options.
While results load, set loading to show the spinner above the list.
Uncontrolled
In a form
Content
- Label the field above it: “Cliente”, “Modelo de peça”. The trigger text is a placeholder instruction: “Selecione o cliente”.
- Pass a search placeholder that names what is searched: “Buscar cliente…”.
- Always pass
emptyContentwith a short message: “Nenhum resultado”. The component has no default. - Option labels are the names users know, not ids. Put the difference between similar options in
description. - With
acceptEmpty, write the placeholder as the empty choice: “Todos os clientes”.
Do and don’t
Accessibility
- The trigger is a
buttonwithrole="combobox",aria-haspopup="listbox"andaria-expanded. It carriesaria-invalid,aria-describedbyandaria-requiredwhen you pass them. - The list is a Radix Popover with a cmdk list. The search input and the list are linked by
aria-controlsandaria-activedescendant; items arerole="option"and the highlighted one isaria-selected. - Keyboard:
EnterorSpaceon the trigger opens the list and moves focus to the search field;ArrowUpandArrowDownmove the highlight;Enterchooses;Escapecloses and returns focus to the trigger. - Name the trigger with
<Label htmlFor={name}>: the triggeridis thenameprop. Without a label, a screen reader reads only the selected text. - Disabled triggers are not focusable. Disabled
fixedOptionsare skipped. - Pass
popoverContainerwhen the combobox is inside a Dialog or Sheet so the list scrolls with the mouse wheel.
Code
import { ControlledCombobox } from "@repo/ui/combobox";
<ControlledCombobox
emptyContent="Nenhum resultado"
fullWidth
inputPlaceholder="Buscar cliente…"
name="customer"
options={[
{ label: "Banco Aurora", value: "aurora" },
{ label: "Cooperativa Meridiano", value: "meridiano" },
]}
placeholder="Selecione o cliente"
setValue={setCustomer}
value={customer}
/>;
Props
ControlledCombobox| Prop | Type | Default | Description |
|---|---|---|---|
acceptEmpty | boolean | false | Adds a first option, labelled with the placeholder, that clears the value. The cleared value is `-` |
disabled | boolean | false | Disables the trigger |
emptyContent | ReactNode | — | Content shown when the search matches nothing. There is no default text, so always pass one |
fixedOptions | { label: string; action: () => void; disabled?: boolean }[] | — | Actions pinned at the top of the list, such as “Criar cliente”. They run `action` and close the list |
fullWidth | boolean | false | Makes the trigger and the list as wide as the container |
inputPlaceholder | string | "Pesquisar..." | Placeholder of the search field in the list |
name | string | — | Used as the trigger `id`, as the name of a hidden input and to build the list id. Must be unique on the page |
options | { value: string; label: string; description?: string }[] | — | The options. `description` is shown under the label |
placeholder | string | "Selecione uma opção" | Trigger text while nothing is selected |
setValue | (value: string) => void | — | Called with the `value` of the chosen option |
value | string | — | Selected option `value`. Use an empty string for none |
ControlledCombobox (more props)| Prop | Type | Default | Description |
|---|---|---|---|
aria-invalid | boolean | — | Turns the border critical. Also passed to `Combobox*` through `FormControl` in `FormCombobox`. |
aria-describedby | string | — | Id of the error or help text. |
triggerSize | ButtonProps['size'] | — | Size of the trigger button. Default is the Button default. |
triggerLeading | ReactNode | — | Content before the label inside the trigger, such as an icon. |
hideTriggerDescription | boolean | false | Keeps the trigger on one line; the description still shows in the list. |
wrapLabels | boolean | false | Wraps long labels, such as dotted field paths, instead of truncating. |
popoverClassName | string | — | Sizing of the list, for example to keep it wider than a narrow trigger. |
popoverContainer | HTMLElement | null | — | Portal target for use inside a Dialog or Sheet. |
open / onOpenChange | boolean / (open: boolean) => void | — | Controls the open state. Uncontrolled when `open` is omitted. |
inputAutoComplete / inputDataAttributes | string / Record<`data-${string}`, string> | — | Attributes for the search input, for example to stop password managers. |
ControlledInputCombobox (differences)| Prop | Type | Default | Description |
|---|---|---|---|
inputValue | string | — | Search text. Required. |
setInputValue | (value: string) => void | — | Called on every keystroke. Required. |
shouldFilter | boolean | true | Set to false when you filter `options` yourself. |
loading | boolean | false | Shows a spinner above the list. |
emptyContent | ReactNode | ComponentType<{ close: () => void }> | — | A component receives `close` to dismiss the list, for example after a create action. |
listFooter | ReactNode | — | Content under the list, separated by a border. |
Combobox (differences)| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | string | — | Initial value. Required. Changing it later replaces the current choice. |
onChange | (value: string) => void | — | Called with the chosen value. |
ariaLabel | string | — | Id of the element that names the field. See Known issues. |
FormCombobox (differences)| Prop | Type | Default | Description |
|---|---|---|---|
form | UseFormReturn | — | The react-hook-form instance. Required. |
name | FieldPath | — | The field name. Required. |
label / description | string | — | Label above and help text under the field. |
onChange | (value: string) => void | — | Extra callback after the form value changes. |
Known issues
| Issue | Effect |
|---|---|
emptyContent has no default, and CommandEmpty renders nothing without children. |
A search with no match shows a blank list unless the caller passes the message. |
ariaLabel is set as aria-labelledby on the hidden input, not on the trigger. |
The trigger has no accessible name of its own; without Label htmlFor={name} a screen reader reads only the selected text. |
Default placeholder (“Selecione uma opção”) and inputPlaceholder (“Pesquisar…”) are Portuguese strings inside the package. |
An app in another language shows Portuguese unless it passes both props on every instance. |
The disabled trigger uses opacity-50, border-0 and a dimmed caret (opacity-40). |
Disabled fields rely on translucency and lose their border; text contrast is lower than other disabled controls. |
Without fullWidth the trigger is capped at max-w-[160px]. |
Labels such as “Financeira Campos Gerais” truncate in the trigger. |
acceptEmpty stores the cleared choice as the string -. |
An option whose value is - is treated as empty, and forms must convert - back to an empty value before submitting. |