Overview
The Command component provides a keyboard-centric interface for quickly finding and executing actions. It features fuzzy search, keyboard navigation, and can be used standalone or within a dialog for a command palette experience.Use cases
- Build command palettes (Cmd+K / Ctrl+K interfaces)
- Create searchable action menus
- Implement quick navigation interfaces
- Build fuzzy search functionality
- Provide keyboard-driven workflows
- Create global search features
Anatomy
The Command component consists of:Command- Root container that manages search and filteringCommand.Dialog- Dialog wrapper for command palette UIsCommand.Input- Search input with iconCommand.List- Scrollable list of filtered resultsCommand.Empty- Empty state when no results foundCommand.Group- Grouped command items with headingCommand.Item- Individual selectable commandCommand.Separator- Visual separator between groupsCommand.Shortcut- Keyboard shortcut display
Props
Command (root)
Inherits all props from the cmdk Command component.string
Controlled search value. Use with
onValueChange for controlled behavior.(value: string) => void
Callback fired when the search value changes.
(value: string, search: string) => number
Custom filter function. Return a number between 0 and 1, where 1 is a perfect match.
boolean
default:"true"
Whether to filter items automatically. Set to false for custom filtering.
string
Additional CSS class names to apply to the command container.
Command.Dialog
boolean
Controlled open state of the dialog.
(open: boolean) => void
Callback fired when the dialog open state changes.
Command.Input
Inherits all props from the cmdk Command.Input component.string
Placeholder text for the search input.
string
Controlled input value.
(value: string) => void
Callback fired when the input value changes.
string
Additional CSS class names to apply to the input.
Command.List
string
Additional CSS class names to apply to the list container.
Command.Empty
string
Additional CSS class names to apply to the empty state.
Command.Group
ReactNode
The heading text or element for the group.
string
Additional CSS class names to apply to the group.
Command.Item
string
The search value for this item. If not provided, children text content is used.
(value: string) => void
Callback fired when the item is selected.
boolean
default:"false"
When true, the item cannot be selected.
string[]
Additional keywords to match against when searching.
string
Additional CSS class names to apply to the item.
Command.Separator
string
Additional CSS class names to apply to the separator.
Command.Shortcut
string
Additional CSS class names to apply to the shortcut display.
Usage
Basic command menu
Command palette dialog
With icons and shortcuts
With custom filtering
Navigation command palette
With keywords for better search
Disabled items
Accessibility
- Built on cmdk (Command Menu) library with full keyboard support
- Keyboard navigation:
- Arrow up/down to navigate items
- Enter to select an item
- Escape to close (when in dialog)
- Tab/Shift+Tab for natural focus flow
- Automatic filtering with fuzzy search
- Screen reader friendly with proper ARIA attributes
- Focus management handles list updates during search
- Search input automatically focused when opened
- Visual indicator shows selected/focused items
Styling customization
Customize the command component using className props:- Search input includes a magnifying glass icon
- Items have hover and selected states
- Keyboard shortcuts are right-aligned with subtle styling
- Empty state is centered with muted text
- Dialog variant has specific padding and overflow handling