Lab/05
Command Palette
Open it with the shortcut or a click, filter as you type, and move through results with the arrow keys.
- Motion
- Keyboard
Click or press ⌘/Ctrl K
lab/command-paletteInstallation
Add Command Palette to your project with the shadcn CLI. The files land in components/lab, ready to edit.
$ pnpm dlx shadcn@latest add @soultel/lab-command-paletteOr by URL: https://asafefe.dev/r/lab-command-palette.json
Brings along
- motion
- lucide-react
- utils
- @soultel/use-reduced-motion-safe
Usage
import { CommandPalette } from "@/components/lab/command-palette"
export function Example() {
return (
<CommandPalette
commands={[
{ id: "new", label: "New Project", group: "Project", shortcut: "N" },
{ id: "theme", label: "Toggle Theme", group: "UI", shortcut: "D" },
]}
onSelect={(cmd) => console.log(cmd.id)}
/>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| commands | Command[] | - | { id, label, group?, shortcut?, color?, onSelect? } for each entry. |
| onSelect | (command: Command) => void | - | Called with the chosen command. |
| open / onOpenChange | boolean / (open: boolean) => void | - | Optional controlled open state. |
| hotkey | string | null | "k" | Toggles with Cmd or Ctrl. null disables it. |
| trigger | boolean | true | Render the search-bar trigger. |
| placeholder | string | "Type a command..." | Input placeholder. |
