Talisman LogoTalisman Logo Design System
Browse documentation
Components

Combobox

A searchable single choice: a trigger that opens a list with a search field, for long or server-loaded lists.

Stableimport { Combobox } from "@repo/ui/combobox";Source

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

O cliente define quais modelos ficam disponíveis.

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 emptyContent with 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

DoLabel the field above it and use the placeholder as an instruction.
Don'tDon't rely on the placeholder alone. Once a value is chosen, nothing says what the field is.

Accessibility

  • The trigger is a button with role="combobox", aria-haspopup="listbox" and aria-expanded. It carries aria-invalid, aria-describedby and aria-required when you pass them.
  • The list is a Radix Popover with a cmdk list. The search input and the list are linked by aria-controls and aria-activedescendant; items are role="option" and the highlighted one is aria-selected.
  • Keyboard: Enter or Space on the trigger opens the list and moves focus to the search field; ArrowUp and ArrowDown move the highlight; Enter chooses; Escape closes and returns focus to the trigger.
  • Name the trigger with <Label htmlFor={name}>: the trigger id is the name prop. Without a label, a screen reader reads only the selected text.
  • Disabled triggers are not focusable. Disabled fixedOptions are skipped.
  • Pass popoverContainer when 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
PropTypeDefaultDescription
acceptEmptybooleanfalseAdds a first option, labelled with the placeholder, that clears the value. The cleared value is `-`
disabledbooleanfalseDisables the trigger
emptyContentReactNode—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
fullWidthbooleanfalseMakes the trigger and the list as wide as the container
inputPlaceholderstring"Pesquisar..."Placeholder of the search field in the list
namestring—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
placeholderstring"Selecione uma opção"Trigger text while nothing is selected
setValue(value: string) => void—Called with the `value` of the chosen option
valuestring—Selected option `value`. Use an empty string for none
ControlledCombobox (more props)
PropTypeDefaultDescription
aria-invalidboolean—Turns the border critical. Also passed to `Combobox*` through `FormControl` in `FormCombobox`.
aria-describedbystring—Id of the error or help text.
triggerSizeButtonProps['size']—Size of the trigger button. Default is the Button default.
triggerLeadingReactNode—Content before the label inside the trigger, such as an icon.
hideTriggerDescriptionbooleanfalseKeeps the trigger on one line; the description still shows in the list.
wrapLabelsbooleanfalseWraps long labels, such as dotted field paths, instead of truncating.
popoverClassNamestring—Sizing of the list, for example to keep it wider than a narrow trigger.
popoverContainerHTMLElement | null—Portal target for use inside a Dialog or Sheet.
open / onOpenChangeboolean / (open: boolean) => void—Controls the open state. Uncontrolled when `open` is omitted.
inputAutoComplete / inputDataAttributesstring / Record<`data-${string}`, string>—Attributes for the search input, for example to stop password managers.
ControlledInputCombobox (differences)
PropTypeDefaultDescription
inputValuestring—Search text. Required.
setInputValue(value: string) => void—Called on every keystroke. Required.
shouldFilterbooleantrueSet to false when you filter `options` yourself.
loadingbooleanfalseShows a spinner above the list.
emptyContentReactNode | ComponentType<{ close: () => void }>—A component receives `close` to dismiss the list, for example after a create action.
listFooterReactNode—Content under the list, separated by a border.
Combobox (differences)
PropTypeDefaultDescription
defaultValuestring—Initial value. Required. Changing it later replaces the current choice.
onChange(value: string) => void—Called with the chosen value.
ariaLabelstring—Id of the element that names the field. See Known issues.
FormCombobox (differences)
PropTypeDefaultDescription
formUseFormReturn—The react-hook-form instance. Required.
nameFieldPath—The field name. Required.
label / descriptionstring—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.
Edit this page on GitHub