Command palettePro
Type to filter, arrow to move, Enter to run. Inline or as a ⌘K dialog.
⌘ K
Project
Rename projectQ3 launch planR
Duplicate projectSame members and settingsD
Workspace
Download briefPDF, 12 pages
Archive projectHide it from the sidebar
Try typing “share”
When to use
- Power-user actions and site search behind ⌘K.
- Long action lists that benefit from type-to-filter.
When not to use
- As the only way to reach an action: keep visible controls too.
- Choosing a form value: use a combobox.
Installation
Usage
Import it from @/components/ui/command-palette after installing.
example.tsx
import * as React from "react";
import { useRouter } from "next/navigation";
import { CommandDialog, useCommandShortcut } from "@/components/ui/command-palette";
export function GlobalSearch() {
const router = useRouter();
const [open, setOpen] = React.useState(false);
useCommandShortcut(() => setOpen((o) => !o));
return (
<CommandDialog
open={open}
onOpenChange={setOpen}
groups={[{ heading: "Pages", items: [{ id: "/settings", label: "Settings", keywords: ["account"] }] }]}
onSelect={(item) => router.push(item.id)}
/>
);
}API reference
CommandPalette
Input plus grouped results with fuzzy matching. Render inline, or use CommandDialog for a modal.
| Prop | Type | Default | Description |
|---|---|---|---|
| groups | { heading: string; items: CommandItem[] }[] | – | Items have id, label, description, icon, shortcut, keywords and onSelect. |
| onSelect | (item: CommandItem) => void | – | Called on Enter or click, after the item's own onSelect. |
| placeholder / emptyMessage | string | – | Input placeholder and no-results text. |
| toolbar | ReactNode | – | Controls under the input, e.g. filter chips. |
| emptyQueryGroups | CommandGroup[] | – | Shown first while the query is empty, e.g. recent items. |
| maxHeight | number | 340 | List height before it scrolls. |
CommandDialog
The palette in a modal with scroll lock, Escape to close and focus return.
| Prop | Type | Default | Description |
|---|---|---|---|
| open / onOpenChange | boolean / (open: boolean) => void | – | Controlled visibility. Accepts every CommandPalette prop too. |
useCommandShortcut
Calls a function on ⌘K or Ctrl+K.
| Prop | Type | Default | Description |
|---|---|---|---|
| onTrigger | () => void | – | Usually toggles the dialog. |
| key | string | "k" | Letter to listen for with ⌘ or Ctrl. |
Keyboard interactions
| Keys | Action |
|---|---|
| ↑or↓ | Move the highlight |
| Ctrl+PorCtrl+N | Same as up and down |
| HomeorEnd | First or last result |
| Enter | Run the highlighted item |
| ⌘KorCtrl+K | Toggle (with useCommandShortcut) |
| Esc | Close the dialog |
Accessibility
- The input is a combobox controlling a listbox through aria-activedescendant.
- Matched text is underlined, not just colored.
- The dialog is aria-modal and returns focus to where it was opened from.
Motion
- The highlight glides between rows (spring, 220ms).
- The list height animates as results filter.
- The dialog scales in from 96%.
Responsive behavior
- The dialog is full-width with 16px gutters on phones, 576px max on desktop.
- The ⌘K hint hides below 640px.
Performance
- Scoring runs on every keystroke over label, description and keywords; fine up to a few thousand items.
- Scrolling keeps the active row visible by moving only the list, never the page.
Notes for AI
- Put synonyms in keywords instead of the label.
- Item ids must be unique across groups.
This page as Markdown, for assistants and coding agents:
/components/command-palette/markdownThe full library index for assistants is at /llms.txt.
Lode222 doc pagesllms.txt