Creatable combobox
A combobox that also accepts a value the user types when it is not in the suggested list.
Nenhum valor definido.
Open the field and type a name that is not in the list. A “Usar” row appears; press Enter to keep what you typed.
When to use
- To suggest common values while still accepting a different one: a source field name, a category, a label.
- When the list is incomplete by nature and blocking an unlisted value would stop the user.
When not to use
- The value must come from the list. Use Combobox, or Select for a short list.
- Creating a record with its own fields. Open a Dialog or Sheet. This component stores only text.
- Search results from a server. Use Autocomplete or Combobox with
ControlledInputCombobox. - 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 |
States
With a typed value
A value that is not in options is shown as typed.
Valor atual: processo.assunto_principal
No suggestions
With an empty options list the field works as a text input with a popup.
Nenhum valor definido.
Disabled
Valor atual: court
Examples
Custom create label
createLabel changes the verb of the create row (“Usar” by default).
Nenhum valor definido.
Content
- Use a verb that says what happens: “Usar” keeps the text, “Criar campo” suggests a new record exists. Do not say “Criar” unless something is created.
- Keep suggestions short; the typed text is trimmed and kept as is.
- The placeholder tells users they can type: “Selecione ou digite o campo”.
Accessibility
- The trigger is a
buttonwithrole="combobox"andaria-expanded. PassariaLabelto name it, or pair it with a visible label. - The list uses Radix Popover with a cmdk list:
role="listbox", options withrole="option", arrow keys move the highlight,Escapecloses. Entercreates the typed value only when no suggestion matches. When suggestions match,Enterchooses the highlighted row, and the create row sits at the top of the list.- The search field is cleared each time the list closes.
- There is no
aria-invalidoraria-describedbysupport. See Known issues.
Code
import { CreatableCombobox } from "@repo/ui/creatable-combobox";
<CreatableCombobox
ariaLabel="Campo de origem"
onValueChange={setField}
options={[
{ label: "Número do processo", value: "case_number" },
{ label: "Vara de origem", value: "court" },
]}
placeholder="Selecione ou digite o campo"
value={field}
/>;
Props
CreatableCombobox| Prop | Type | Default | Description |
|---|---|---|---|
ariaLabel | string | — | Accessible name of the trigger |
createLabel | string | "Usar" | Text before the typed value in the create row |
disabled | boolean | false | Disables the trigger |
fullWidth | boolean | false | Makes the trigger as wide as the container |
inputPlaceholder | string | "Pesquisar ou digitar…" | Placeholder of the search field in the list |
onValueChange | (value: string) => void | — | Called with the option `value`, or with the trimmed text when the user creates a value |
options | { value: string; label: string }[] | — | Suggested options |
placeholder | string | "Selecione uma opção…" | Trigger text while there is no value |
value | string | — | Current value: an option `value` or free text. Use an empty string for none |
CreatableCombobox (more props)| Prop | Type | Default | Description |
|---|---|---|---|
triggerClassName | string | — | Extra class for the trigger. Layout only. |
popoverContainer | HTMLElement | null | — | Portal target for use inside a Dialog or Sheet so the list scrolls. |
Known issues
| Issue | Effect |
|---|---|
| “Nenhuma opção encontrada” is hardcoded and has no prop. | It cannot be translated, and it shows only when the input is empty and there are no options. |
The component has no aria-invalid, aria-describedby or error styling. |
Validation errors cannot be shown on the field, so it is unsuitable for required fields without extra work around it. |
The create row is a raw button with hover:bg-accent and text-sm, not a CommandItem, when nothing matches. |
It is not part of the arrow-key list: it never shows the highlighted state of an option and is reached with Tab or Enter. |
The trigger is capped at max-w-[200px] unless fullWidth. |
Long field paths truncate. |