Command menu
A searchable action list, the ⌘K palette
Installation
npx shadcn@latest add @sudokw/components-command-menuimport { CommandMenu } from "@gpuixui/components";Usage
import {
CommandMenu,
CommandMenuEmpty,
CommandMenuInput,
CommandMenuList,
} from "@gpuixui/components/command-menu";
const actions = [
{
id: "new-file",
label: "New file",
group: "File",
shortcut: "⌘N",
perform: newFile,
},
{
id: "toggle-sidebar",
label: "Toggle sidebar",
group: "View",
shortcut: "⌘B",
perform: toggleSidebar,
},
];
<CommandMenu open={open} onOpenChange={setOpen} actions={actions}>
<CommandMenuInput placeholder="Type a command…" />
<CommandMenuList />
<CommandMenuEmpty>No matching commands</CommandMenuEmpty>
</CommandMenu>;Composition
CommandMenu
├── CommandMenuInput
├── CommandMenuList
│ └── CommandMenuItem
└── CommandMenuEmptyAPI reference
| Part | Renders | Props |
|---|---|---|
CommandMenu | the composed Dialog surface | open (required), onOpenChange (required), actions (required; a stored value that is not a list paints the empty state), recents (a stored value that is not a list carries no recents), filter, children |
CommandMenuInput | host <input> | placeholder (default "Type a command…"; an empty field announces it as aria-description), label (default "Search commands"), className |
CommandMenuList | scrolling match column | className; the root's ranked matches are its content |
CommandMenuItem | one runnable row | action (required), className |
CommandMenuEmpty | the no-match message | children (default No matching commands), className |
Keyboard
- Arrow DownArrow UpCtrl+NCtrl+P
- moves the highlight
- HomeEnd
- the first or last action
- Escape
- closes the palette
- Tab
- keeps focus inside the dialog
Enter runs the highlighted action through the search field's submit.
read from command-menu.tsx, modal.ts
Edit this page on GitHubapps/docs/content/docs/components/command-menu.mdx