Use cases
- Command palette (⌘K) — global search and action launcher in a dialog overlay.
- Inline search — filterable list embedded directly in the page (e.g. sidebar search, settings filter).
- Combobox replacement — when a searchable dropdown needs grouped items and keyboard navigation.
When NOT to use
- Simple dropdown with fewer than 10 static items → use
Select. - Full-text search with server-side results → use a search input with debounced fetch.
Anatomy
<Command>
<CommandInput placeholder="Search..." />
<CommandList>
<CommandEmpty>No results.</CommandEmpty>
<CommandGroup heading="Actions">
<CommandItem>Dashboard</CommandItem>
<CommandItem>Settings</CommandItem>
</CommandGroup>
</CommandList>
</Command>Dialog mode
Wrap in CommandDialog for a ⌘K overlay.
<CommandDialog open={open} onOpenChange={setOpen}>
<CommandInput placeholder="Type a command..." />
<CommandList>...</CommandList>
</CommandDialog>Sub-components
| Component | Purpose |
|---|---|
Command | Root — filterable container. |
CommandDialog | Dialog-mounted variant. |
CommandInput | Search input with icon. |
CommandList | Scrollable results container. |
CommandEmpty | Shown when filter matches nothing. |
CommandGroup | Labelled group of items. |
CommandItem | Selectable result. |
CommandSeparator | Visual divider between groups. |
CommandShortcut | Right-aligned shortcut hint inside an item. |
Composition
- Use
CommandDialogfor aCmd+Kcommand palette. It wraps Command in a Dialog. - Group related items with
CommandGroupand label each group. CommandEmptyrenders when the filter matches nothing — use it for a "No results" message.CommandShortcutrenders keyboard shortcut hints right-aligned inside an item.
Related
- Dialog — used internally by
CommandDialog. - Combobox — searchable dropdown for form fields.
- SearchField — standalone search input.