Command
⌘K palette: filterable groups, arrow-key highlight, Enter to run, keyword matching. Inline or as CommandDialog with a global shortcut; the first Esc clears, the second closes.
↑ ↓ to move · Enter to run · try the site-wide palette with ⌘K / Ctrl K
"use client";import { FileText } from "lucide-react";import { useRouter } from "next/navigation";import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList,} from "@/components/ui/command";const pages = [ { href: "/", title: "Home" }, { href: "/blog", title: "Blog" }, { href: "/clips", title: "Clips" },];export function SitePalette() { const router = useRouter(); return ( <CommandDialog shortcut="mod+k"> <CommandInput placeholder="Search pages…" /> <CommandList> <CommandEmpty>No pages found.</CommandEmpty> <CommandGroup heading="Pages"> {pages.map((p) => ( <CommandItem key={p.href} onSelect={() => router.push(p.href)}> <FileText /> {p.title} </CommandItem> ))} </CommandGroup> </CommandList> </CommandDialog> );}<Command>
Filterable, keyboard-driven list. Arrows/Home/End move, Enter selects. Use inline or in CommandDialog.
children*ReactNodeCommandInputandCommandList.close() => voidCalled after a selection; CommandDialog passes its own close.
| Prop | Type | Default |
|---|---|---|
children*
| ReactNode | — |
closeCalled after a selection; CommandDialog passes its own close. | () => void | — |
<CommandInput>
labeldefault"Search commands"stringAccessible name of the input.
placeholderdefault"Type a command or search…"stringInput placeholder.
| Prop | Type | Default |
|---|---|---|
labelAccessible name of the input. | string | "Search commands" |
placeholderInput placeholder. | string | "Type a command or search…" |
<CommandList>
Scrollable results. Shows CommandEmpty only when no option matches.
children*ReactNodeGroups, items, separators and
CommandEmpty.labeldefault"Results"stringAccessible name of the listbox.
| Prop | Type | Default |
|---|---|---|
children*Groups, items, separators and | ReactNode | — |
labelAccessible name of the listbox. | string | "Results" |
<CommandEmpty>
Also accepts every <div> prop (none of its own).
<CommandGroup>
Hides itself when none of its items match.
children*ReactNodeCommandItems.headingstringVisible group title.
| Prop | Type | Default |
|---|---|---|
children*
| ReactNode | — |
headingVisible group title. | string | — |
<CommandSeparator>
Hidden while filtering, when groups collapse and separators would stack up.
<CommandItem>
children*ReactNodeItem content, e.g. an icon and a label.
disabledbooleanShown but not selectable.
keepOpenbooleanInside CommandDialog: stay open after selecting.
keywordsreadonly string[]Extra search terms, e.g. ["settings", "preferences"].
onSelect(value: string) => voidCalled with the item's
valueon click or Enter.valuestringMatched against the query and used for selection. Defaults to the item's text.
| Prop | Type | Default |
|---|---|---|
children*Item content, e.g. an icon and a label. | ReactNode | — |
disabledShown but not selectable. | boolean | — |
keepOpenInside CommandDialog: stay open after selecting. | boolean | — |
keywordsExtra search terms, e.g. ["settings", "preferences"]. | readonly string[] | — |
onSelectCalled with the item's | (value: string) => void | — |
valueMatched against the query and used for selection. Defaults to the item's text. | string | — |
<CommandDialog>
Command palette: Command in a Dialog, toggled by a global shortcut. Selecting closes it.
children*ReactNodeCommandInputandCommandList.onOpenChange(open: boolean) => voidCalled on the shortcut, Esc, outside click or a selection.
openbooleanControlled state; pair with
onOpenChange.shortcutdefault"mod+k"false | `mod+${string}`Global toggle, e.g. "mod+k" (⌘ on Mac, Ctrl elsewhere). Pass false to disable.
titledefault"Command palette"stringAccessible dialog title (visually hidden).
| Prop | Type | Default |
|---|---|---|
children*
| ReactNode | — |
onOpenChangeCalled on the shortcut, Esc, outside click or a selection. | (open: boolean) => void | — |
openControlled state; pair with | boolean | — |
shortcutGlobal toggle, e.g. "mod+k" (⌘ on Mac, Ctrl elsewhere). Pass false to disable. | false | `mod+${string}` | "mod+k" |
titleAccessible dialog title (visually hidden). | string | "Command palette" |
* required. Every component also takes className.