Skip to content

Command Menu

A ⌘K palette: fuzzy search with highlighted matches, groups and shortcuts, nested pages, recent picks and async results - every step by keyboard.

On this page
Used for
  • Jump to a run
  • Switch model
  • Quick actions
  • Search tickets

Examples

Installation

npx knowns-ui@latest add command-menu
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

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[]
Defaultfuzzy 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[]
Defaultfirst-seen
Group order with an empty search. While typing, the best matches lead.
recents / onRecentsChange / maxRecents
string[] / fn / number
Defaultkept inside / - / 5
Picked ids, shown first as Recent while the search is empty. 0 turns it off.
open / defaultOpen / onOpenChange
boolean
Defaultfalse
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.

What it handles

  1. 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.
  2. 02Matches fuzzily, ranks the best first and highlights the matched characters; extra words in keywords also match.
  3. 03Groups items by group in the order you give, puts Recent first while the search is empty, and keeps maxRecents of the last picks.
  4. 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.
  5. 05Runs load for results that depend on the query, debounced by debounce, aborting the previous request and showing a Spinner while it waits.
  6. 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

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" }).

Need help?

Stuck on Command Menu, or found something off? We read every message.