Command palette
A search box over a list of actions. Type to filter, move with the arrow keys, press Enter to run. Groups hold related actions, each row can carry an icon and a shortcut, and the palette can live inline on a page or open as a dialog from anywhere.
Install
npx shadcn@latest add @nelumbo/commandInline
Groups are separated by space, not lines. The highlighted row sits on a raised pill that springs from row to row with the pointer and the arrow keys, and its icon tile turns inverse. Shortcuts written as one string, like ⌘N, split into keycaps and are read as one. Disabled rows stay visible at 40%.
Dialog
CommandDialog opens over the page from a button or from ⌘K (Ctrl K elsewhere). Escape closes it. Its title and description are for screen readers only.
Empty state
CommandEmpty shows when nothing matches. The search is controlled here; clear it to see the list again.
Loading
CommandLoading shows inside the list while results are fetched. It is announced politely, and the spinner stops under reduced motion.
Usage
import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut,} from "@/components/ui/command"const [open, setOpen] = React.useState(false)React.useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key.toLowerCase() === "k" && (e.metaKey || e.ctrlKey)) { e.preventDefault() setOpen((o) => !o) } } window.addEventListener("keydown", onKey) return () => window.removeEventListener("keydown", onKey)}, [])<CommandDialog open={open} onOpenChange={setOpen}> <CommandInput placeholder="Type a command…" /> <CommandList> <CommandEmpty>No results.</CommandEmpty> <CommandGroup heading="Create"> <CommandItem onSelect={() => { newFile(); setOpen(false) }}> <Icon name="note_add" /> New file <CommandShortcut>⌘N</CommandShortcut> </CommandItem> </CommandGroup> <CommandSeparator /> </CommandList></CommandDialog>Props
| Prop | Type | Default | Notes |
|---|---|---|---|
Command | Rounded surface-container-high container with menu elevation. Extra props go to cmdk | ||
CommandDialog open / onOpenChange | boolean / (open) => void | Controlled, like Dialog | |
CommandDialog title / description | string | "Command palette" | Visually hidden, read by screen readers |
CommandInput placeholder / value / onValueChange | string | Controlled search text | |
CommandList | Scrolls past about 22rem (70dvh) | ||
CommandEmpty | ReactNode | Shown when nothing matches | |
CommandLoading | ReactNode | Spinner and “Searching…” | Put it inside CommandList while results load |
CommandGroup heading | ReactNode | Muted label above the rows, no rule | |
CommandItem onSelect / value | (value) => void / string | Enter or click runs it; value defaults to its text | |
CommandItem disabled | boolean | false | Shown at 40%, can't be highlighted |
CommandItem keywords | string[] | Extra terms that match the search | |
CommandShortcut | ReactNode | Keycap on the trailing edge | |
CommandSeparator | Empty spacer between groups, hidden while searching |