Command
A search field over a list of actions or pages, filtered as you type: the command palette, in a dialog or inline.
Installation
Or with the shadcn CLI, from the registry:
Usage
Command is Base UI's Autocomplete, inline: the list is always shown
and the first match is highlighted, so Enter runs it. Give the items (or groups of items, rendered with CommandGroup,
CommandGroupLabel and CommandCollection, as in the demo at the top) to Command, not to the list. onSelect runs on
a click or on Enter; the field keeps what was typed.
In a dialog: the ⌘K palette
CommandDialog puts a Command in a dialog near the top of the screen, with a title for screen readers. Open it from a
button and from a shortcut; this site's search is one.
Pick an action to run it.
Coming from shadcn
shadcn's Command is built on cmdk, which filters the items it finds in its children. This one filters the items you
give it and renders the list from a function, as Base UI does. With shadcn:
With Rasengan UI:
For your own ranking, pass filteredItems (the items to show, in order) and control value, as this site's search does.
Villages
The list highlights the item under the arrow keys in the village's highlight colour; group labels are in mono capitals.
Accessibility
- The field has
role="combobox"and the listrole="listbox": the arrow keys move the highlight and screen readers announce it, Enter runs the item. - Name the field with
aria-label(or a label) when the placeholder is the only text. CommandDialoghas a visually hidden title and description; Escape closes it and focus returns to what opened it.
API reference
| Component | Base UI part | Props |
|---|---|---|
Command | Autocomplete.Root (inline, always open) | items, filteredItems, value, onValueChange, itemToStringValue, autoHighlight (default "always")… |
CommandInput | Input | |
CommandEmpty | Empty | Before CommandList |
CommandList | List | A function of each item or group |
CommandGroup, CommandGroupLabel, CommandCollection | Group, GroupLabel, Collection | |
CommandItem | Item | value, onSelect |
CommandSeparator | Separator | |
CommandShortcut | A Kbd at the end of an item | |
CommandDialog | Dialog | open, onOpenChange, title, description |