Command
A search field with a filtered list of items, built on cmdk, for command palettes and as the base of the other selection components.
Type to filter. Use the arrow keys to highlight an item.
When to use
- A command palette or global search that opens pages and runs actions (
CommandDialog). - A searchable list that is always visible, such as a side panel.
- To build a new selection control that Combobox, Creatable combobox and Autocomplete do not cover.
When not to use
- Choosing a value for a form field. Use Select for short lists or Combobox for searchable ones; both already wrap
Commandin a popover. - A menu of actions on one element. Use a Dropdown menu.
- A modal that asks a question. Use Dialog.
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 |
Anatomy
| Part | Role |
|---|---|
Command |
The root. Owns the search text, the highlight and the filter. |
CommandInput |
The search field, with a search icon. |
CommandList |
Scrollable area, up to 300px high. |
CommandGroup |
A set of items. heading names it. |
CommandItem |
One result. onSelect runs when chosen; disabled blocks it. |
CommandSeparator |
A line between groups. |
CommandShortcut |
A key hint aligned to the right of an item. |
CommandEmpty |
Shown when nothing matches. It has no default text. |
CommandDialog |
Command inside a modal Dialog, for a global palette. |
Examples
Palette with groups
Searching by label and description
By default, cmdk matches what is in the item value. When the value is an id and the user reads a label, pass options so the search reads the label and description instead. The search ignores accents and case.
Busque por “reu” ou “mérito”: a busca ignora acentos e também lê a descrição.
Resposta do réu à petição inicial
Peça que abre o processo
Decisão do juízo sobre o mérito
Resposta do autor à contestação
Custom filter
Use filter when you need your own rule. Call filterOptions inside it to keep the built-in behavior and add to it.
In a dialog
CommandDialog needs a title and a description. They are read by screen readers and are not visible.
Filtering
filterOptions(value, search, options?) is the function Command uses when you do not pass filter. It returns 1 to show an item and 0 to hide it. There is no ranking: matching items keep the order you gave them.
| Rule | Detail |
|---|---|
| Empty search | Every item matches. |
| Normalization | Both sides lose accents and special characters, become lowercase and use - for spaces, with no length limit. “Réplica” matches “replica”. |
With options |
The item is found by its value, and the search runs over its label and description together. |
Without options (or value not in it) |
The search runs over the item value. |
| Multiple words | They match as a sequence: “petição inicial” matches, “inicial petição” does not. |
| Performance | options is indexed once and cached by array identity. Pass a stable array (a constant or useMemo), not a new one on every render. |
Set shouldFilter={false} when the items already come filtered, such as server results, and render only what should be visible.
Content
- Group headings name the kind of result: “Páginas”, “Ações”.
- Items are short and start with the noun or the verb: “Tarefas”, “Buscar processo”.
- Always add a
CommandEmptywith a short message: “Nenhum resultado”. - Show shortcuts with
CommandShortcut, and use real keys: “⌘K”. - Icons are optional; mark them
aria-hiddenbecause the label already says it.
Do and don’t
value=“defense”, label “Contestação”
value=“defense”, no options
Accessibility
- Built on cmdk:
CommandInputisrole="combobox"linked to the list byaria-controlsandaria-activedescendant;CommandListisrole="listbox"; items arerole="option"witharia-selectedandaria-disabled. - Focus stays in the input while the highlight moves, so users can keep typing.
- Keyboard:
ArrowDownandArrowUpmove,HomeandEndgo to the first and last item,EnterrunsonSelect. Disabled items are skipped. CommandDialoguses Radix Dialog: focus moves in on open,Escapecloses it, and focus returns to the opener. Its requiredtitleanddescriptionbecome the dialog name and description.- Icons inside items are decorative; give them
aria-hidden.
Code
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@repo/ui/command";
<Command>
<CommandInput placeholder="Buscar páginas e ações…" />
<CommandList>
<CommandEmpty>Nenhum resultado</CommandEmpty>
<CommandGroup heading="Páginas">
<CommandItem onSelect={openTasks}>Tarefas</CommandItem>
</CommandGroup>
</CommandList>
</Command>;
Props
Command| Prop | Type | Default | Description |
|---|---|---|---|
filter | (value: string, search: string, keywords?: string[]) => number | — | Custom match function. Return 1 to show the item and 0 to hide it. Replaces the built-in `filterOptions` |
onValueChange | (value: string) => void | — | Called when the highlighted item changes |
options | { value: string; label: string; description?: string }[] | [] | Label and description of each item, so search matches what the user reads and not only the item `value` |
shouldFilter | boolean | true | Set to false when you filter the items yourself, for example with results from a server |
value | string | — | Controlled highlighted item |
CommandDialog| Prop | Type | Default | Description |
|---|---|---|---|
open / onOpenChange | boolean / (open: boolean) => void | — | Controls the dialog. |
title | ReactNode | — | Accessible name of the dialog, not visible. Required. |
description | ReactNode | — | Accessible description of the dialog, not visible. Required. |
shouldFilter | boolean | true | Set to false when you filter the items. |
CommandItem| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Identifies the item for filtering and selection. Defaults to its text. |
onSelect | (value: string) => void | — | Runs on click or `Enter`. |
disabled | boolean | false | Skips the item in navigation and blocks selection. |
keywords | string[] | — | Extra terms the default cmdk filter can match. |
CommandInput| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | — | Text of the empty field. Pass translated copy. |
value / onValueChange | string / (value: string) => void | — | Controls the search text. |
CommandGroup| Prop | Type | Default | Description |
|---|---|---|---|
heading | ReactNode | — | Label of the group. |
filterOptions(value, search, options?)| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | The item value. |
search | string | — | The current search text. |
options | { value; label; description? }[] | — | Optional. Enables label and description matching. |
Known issues
| Issue | Effect |
|---|---|
CommandInput sets placeholder:text-primary. |
The placeholder has the same color as typed text, so an empty field looks filled in. |
CommandDialog does not pass closeLabel to DialogContent. |
The corner close button is named “Close” in English and an app cannot translate it. |
CommandDialog sets md:min-w-[800px]. |
The palette cannot be narrower than 800px on medium screens and above, and overflows small laptop windows. |
CommandEmpty has no default text. |
An empty result shows a blank area unless you add a message. |
filterOptions removes characters other than letters, digits, spaces and hyphens, so a search made only of punctuation (“.”, “/”) becomes empty. |
Typing only punctuation matches every item instead of none. |
Disabled items use data-[disabled=true]:opacity-50. |
Translucent dimming rather than a disabled token, with lower contrast. |