Components / Navigation
Command Palette
A ⌘K command menu with search, groups, shortcuts and full keyboard navigation.
Click, or press ⌘K / Ctrl+K. Use ↑ ↓ and Enter.
Installation
Requires React 18+ and Tailwind CSS.
- 1
Install dependencies
$ npm install motion - 2
Add the component
Copy the code from the Code tab above into
components/ui/command-palette.tsx. - 3
Use it
example.tsximport { CommandPalette } from "@/components/ui/command-palette"; const icon = (d: string) => ( <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> <path d={d} /> </svg> ); const commands = [ { id: "new-file", label: "New file", group: "Actions", shortcut: "⌘N", icon: icon("M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9zM14 3v6h6M12 12v6M9 15h6") }, { id: "new-project", label: "New project", group: "Actions", shortcut: "⇧⌘N", icon: icon("M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z") }, { id: "invite", label: "Invite teammate", group: "Actions", icon: icon("M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM19 8v6M22 11h-6") }, { id: "dashboard", label: "Go to Dashboard", group: "Navigation", icon: icon("M3 3h7v9H3zM14 3h7v5h-7zM14 12h7v9h-7zM3 16h7v5H3z") }, { id: "settings", label: "Go to Settings", group: "Navigation", shortcut: "⌘,", icon: icon("M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z") }, { id: "theme", label: "Toggle theme", group: "Preferences", shortcut: "⌘D", icon: icon("M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z") }, ]; export default function CommandPaletteDemo() { return ( <div className="flex flex-col items-center gap-3"> <CommandPalette commands={commands} /> <p className="text-xs text-zinc-500">Click, or press ⌘K / Ctrl+K. Use ↑ ↓ and Enter.</p> </div> ); }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| commands | { id; label; group?; icon?; shortcut?; onSelect? }[] | — | Commands to show. |
| placeholder | string | "Type a command or search…" | Search placeholder. |
| hotkey | boolean | true | Open with ⌘K / Ctrl+K. |
| showTrigger | boolean | true | Render the built-in Search… button. |