Command
Navigation
Keyboard
cmdk
A command palette component for quick navigation and actions. Built on cmdk for fast, accessible keyboard-first interactions.
Basic Command
A static command menu with groups and items
No results found.
Calendar
Search Emoji
Calculator
ProfileP
BillingB
SettingsS
Command Dialog
Command palette in a dialog overlay, triggered by keyboard shortcut
Press ⌘K to open the command palette
With Keyboard Shortcuts
Display keyboard shortcuts alongside command items
No results found.
New File⌘N
Search⌘F
Preferences⌘,
Usage
How to implement the Command component
import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut,} from '@/components/ui/command'
// Basic usage<Command> <CommandInput placeholder="Type a command..." /> <CommandList> <CommandEmpty>No results found.</CommandEmpty> <CommandGroup heading="Suggestions"> <CommandItem> <Calendar className="mr-2 h-4 w-4" /> <span>Calendar</span> </CommandItem> </CommandGroup> </CommandList></Command>
// As a dialog with keyboard shortcutconst [open, setOpen] = React.useState(false)
React.useEffect(() => { const down = (e: KeyboardEvent) => { if (e.key === 'k' && (e.metaKey || e.ctrlKey)) { e.preventDefault() setOpen((open) => !open) } } document.addEventListener('keydown', down) return () => document.removeEventListener('keydown', down)}, [])
<CommandDialog open={open} onOpenChange={setOpen}> <CommandInput placeholder="Search..." /> <CommandList> <CommandGroup heading="Actions"> <CommandItem onSelect={() => setOpen(false)}> <span>Action</span> <CommandShortcut>⌘A</CommandShortcut> </CommandItem> </CommandGroup> </CommandList></CommandDialog>Component Props
API reference for Command components
| Prop | Type | Default | Description |
|---|---|---|---|
Command | React.ComponentProps<typeof CommandPrimitive> | — | Root command container, accepts all cmdk props |
CommandDialog | { open, onOpenChange, children } | — | Command in a dialog overlay |
CommandInput | React.ComponentProps<typeof CommandPrimitive.Input> | — | Search input field |
CommandList | React.ComponentProps<typeof CommandPrimitive.List> | — | Scrollable list container |
CommandEmpty | React.ComponentProps<typeof CommandPrimitive.Empty> | — | Shown when no results |
CommandGroup | { heading?: string } & props | — | Group of related items |
CommandItem | { onSelect?: () => void } & props | — | Individual command item |
CommandShortcut | React.HTMLAttributes<HTMLSpanElement> | — | Keyboard shortcut display |
CommandSeparator | React.ComponentProps<typeof CommandPrimitive.Separator> | — | Visual separator between groups |
Features
Command palette capabilities
- Fuzzy search: Built-in fuzzy filtering of command items
- Keyboard navigation: Arrow keys, Enter, and Escape support
- Command+K shortcut: Standard keyboard shortcut integration
- Grouped items: Organize commands into logical groups
- Shortcuts display: Show keyboard shortcuts for commands
- Dialog mode: Open as overlay dialog or inline
- Accessible: Full ARIA support for screen readers
- Dark mode: Automatic dark mode styling