A ⌘K palette: fuzzy search with highlighted matches, groups and shortcuts, nested pages, recent picks and async results - every step by keyboard.
Used for
- Jump to a run
- Switch model
- Quick actions
- Search tickets
Examples
Installation
npx knowns-ui@latest add command-menuFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Command menu from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/command-menu
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add command-menu
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/kbd.tsx
- components/ui/knowns/spinner.tsx
- components/ui/knowns/command-menu/command-menu.tsx
- components/ui/knowns/command-menu/command-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/command-menu, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "command-menu" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- items
CommandItem[]- { id, label, description?, badge?, meta?, icon?, shortcut?: string[], keywords?, group?, disabled?, page?, onSelect?, keepOpen? }. label is fuzzy-matched and the hit characters are highlighted; keywords match as substrings. badge sits right after the label (e.g. a Pro mark); meta is quiet text on the right (e.g. where a page lives).
- search
(items, query) => CommandItem[]- Default
fuzzy match - Your own ranking for the root items, such as an index that knows synonyms: return the matches best first. Their order is kept; the label still highlights where it fuzzy-matches.
- pages
CommandPage[]- Default
[] - { id, title, placeholder?, items?, load?, groups? }. An item with page drills in (Enter); Backspace on an empty search, or Escape, goes back. The page title shows as a crumb in the field.
- load / loadGroup / debounce
(query, signal) => Promise<CommandItem[]> / string / ms- Default
- / "Results" / 150 - Async results while typing (root), or for a page's whole list. Stale requests are aborted; a spinner and skeleton rows show while loading.
- groups
string[]- Default
first-seen - Group order with an empty search. While typing, the best matches lead.
- recents / onRecentsChange / maxRecents
string[] / fn / number- Default
kept inside / - / 5 - Picked ids, shown first as Recent while the search is empty. 0 turns it off.
- open / defaultOpen / onOpenChange
boolean- Default
false - Native modal <dialog>: focus trap, top layer, Escape. A backdrop click closes.
- hotkey
string|false- Default
"mod+k" - Toggles the menu from anywhere: ⌘K on macOS, Ctrl+K elsewhere. Any combo like "mod+shift+p".
- onSelect / empty / placeholder
fn / (query, { setQuery }) => ReactNode / string- onSelect runs after the item's own; empty replaces “No results for …”, and setQuery lets it offer other searches.
- CommandMenuTrigger
{ onClick, label?, hotkey? }- The usual search-looking button with the shortcut shown as Kbd (aria-keyshortcuts).
- motion
CSS only- The panel scales from 0.98 and fades in, then out on close (a real exit); the backdrop fades with it; the list height follows the result count; one highlight glides between rows; the first rows rise in on open. Reduced motion keeps opacity only.
- a11y
combobox + listbox- The field is role=combobox with aria-activedescendant; rows are options in labelled groups (aria-disabled, aria-selected). ↑ ↓ wrap and skip disabled rows; the result count is announced.
| Prop | Type | Default | Description |
|---|---|---|---|
| items | CommandItem[] | - | { id, label, description?, badge?, meta?, icon?, shortcut?: string[], keywords?, group?, disabled?, page?, onSelect?, keepOpen? }. label is fuzzy-matched and the hit characters are highlighted; keywords match as substrings. badge sits right after the label (e.g. a Pro mark); meta is quiet text on the right (e.g. where a page lives). |
| search | (items, query) => CommandItem[] | fuzzy match | Your own ranking for the root items, such as an index that knows synonyms: return the matches best first. Their order is kept; the label still highlights where it fuzzy-matches. |
| pages | CommandPage[] | [] | { id, title, placeholder?, items?, load?, groups? }. An item with page drills in (Enter); Backspace on an empty search, or Escape, goes back. The page title shows as a crumb in the field. |
| load / loadGroup / debounce | (query, signal) => Promise<CommandItem[]> / string / ms | - / "Results" / 150 | Async results while typing (root), or for a page's whole list. Stale requests are aborted; a spinner and skeleton rows show while loading. |
| groups | string[] | first-seen | Group order with an empty search. While typing, the best matches lead. |
| recents / onRecentsChange / maxRecents | string[] / fn / number | kept inside / - / 5 | Picked ids, shown first as Recent while the search is empty. 0 turns it off. |
| open / defaultOpen / onOpenChange | boolean | false | Native modal <dialog>: focus trap, top layer, Escape. A backdrop click closes. |
| hotkey | string | false | "mod+k" | Toggles the menu from anywhere: ⌘K on macOS, Ctrl+K elsewhere. Any combo like "mod+shift+p". |
| onSelect / empty / placeholder | fn / (query, { setQuery }) => ReactNode / string | - | onSelect runs after the item's own; empty replaces “No results for …”, and setQuery lets it offer other searches. |
| CommandMenuTrigger | { onClick, label?, hotkey? } | - | The usual search-looking button with the shortcut shown as Kbd (aria-keyshortcuts). |
| motion | CSS only | - | The panel scales from 0.98 and fades in, then out on close (a real exit); the backdrop fades with it; the list height follows the result count; one highlight glides between rows; the first rows rise in on open. Reduced motion keeps opacity only. |
| a11y | combobox + listbox | - | The field is role=combobox with aria-activedescendant; rows are options in labelled groups (aria-disabled, aria-selected). ↑ ↓ wrap and skip disabled rows; the result count is announced. |
What it handles
- 01Opens on Cmd+K or Ctrl+K through hotkey, shows the keys on the trigger with Kbd, and lets you turn the shortcut off with false.
- 02Matches fuzzily, ranks the best first and highlights the matched characters; extra words in keywords also match.
- 03Groups items by group in the order you give, puts Recent first while the search is empty, and keeps maxRecents of the last picks.
- 04Opens nested pages with Enter on an item that has page, and goes back with Backspace on an empty search or Escape; the page title shows as a crumb in the field.
- 05Runs load for results that depend on the query, debounced by debounce, aborting the previous request and showing a Spinner while it waits.
- 06Moves with ArrowUp, ArrowDown, Home and End over enabled rows only, runs onSelect on Enter, and closes unless the item sets keepOpen.
States
- First render
- Nothing. The menu is closed until the hotkey or open
- none
- Open
- The panel and backdrop fade in; they fade out a little quicker
- 120ms, opacity only
- Typing
- The list is re-ranked at once, with no stagger
- none, at once
- Active row moves
- The highlight sits on the new row with no glide
- none
- Loading with no rows
- Three placeholder rows pulse until results arrive
- none
- Reduced motion
- The fade is instant
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The menu is closed until the hotkey or open | none |
| Open | The panel and backdrop fade in; they fade out a little quicker | 120ms, opacity only |
| Typing | The list is re-ranked at once, with no stagger | none, at once |
| Active row moves | The highlight sits on the new row with no glide | none |
| Loading with no rows | Three placeholder rows pulse until results arrive | none |
| Reduced motion | The fade is instant | 0ms |
Works with
When to use
When to use
- A ⌘K palette for jumping and running commands across the app, all by keyboard.
When not to use
- A few actions on one item: use Menu.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Command Menu to my app and wire it to my own data.
- I need a ⌘K palette for jumping and running commands across the app, all by keyboard. Set that up with the Knowns UI Command Menu.
- Which Command Menu props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "command-menu" }) and search_docs({ query: "command menu" }).