CommandMenu

Cmd+K command palette with fuzzy search over grouped commands

Category: overlay · WCAG 2.2-AA · overlay, command, palette, search, cmdk, keyboard, scope, fuzzy

States

Props

PropTypeDefaultDescription
openbooleanWhether the component is open (controlled).
onOpenChange(open: boolean) => voidCalled with the next open state when it changes.
groupsCommandGroup[]The grouped commands to display.
placeholderstringType a command or search…Placeholder text shown when the field is empty.
emptyLabelstringNo results foundText shown when no commands match the query.
hotkeybooleantrueGlobal Cmd/Ctrl+K toggles the menu via onOpenChange
labelstringCommand menuText label for the control.
loadingbooleanfalseShows a loading spinner in place of the empty state (for async items)
onQueryChange(query: string) => voidFires on every query keystroke — use to fetch async items
scopesCommandScope[][]Selectable filter scopes. Renders a scope bar + chip; a scope activates by clicking its pill, typing its prefix (c:/c ), or cycling with Tab, and filters to groups tagged with a matching scope (plus untagged groups).
classNamestringAdditional CSS class names merged onto the root element.

Design tokens

When to use

When not to use

How to build an accessible CommandMenu in React →

Examples

Basic command menu

<CommandMenu
  open={open}
  onOpenChange={setOpen}
  groups={[
    {
      heading: 'Actions',
      items: [
        { id: 'new', label: 'New file', shortcut: ['⌘', 'N'], onSelect: createFile },
        { id: 'search', label: 'Search docs', keywords: ['find'], onSelect: openSearch },
      ],
    },
  ]}
/>

Scoped search with rich rows and inline actions

A scope chip filters to Clusters, matched glyphs are highlighted, each row carries a mono metadata line + status pill, and the selected row reveals Open (↵) / New tab (⌘↵) inline actions.

<CommandMenu
  open={open}
  onOpenChange={setOpen}
  scopes={[
    { id: 'clusters', label: 'Clusters', prefix: 'c' },
    { id: 'orgs', label: 'Orgs', prefix: 'o' },
    { id: 'commands', label: 'Commands', prefix: '>' },
  ]}
  groups={[
    {
      heading: 'Clusters',
      scope: 'clusters',
      items: [
        {
          id: 'prod-eu',
          label: 'prod-eu-central-1',
          description: 'eu-central-1 · Enterprise · c9f21a04',
          status: { label: 'Healthy', tone: 'healthy' },
          actions: [
            { id: 'open', label: 'Open', shortcut: ['↵'], onSelect: () => open('prod-eu') },
            { id: 'tab', label: 'New tab', shortcut: ['⌘', '↵'], onSelect: () => openInTab('prod-eu') },
          ],
        },
      ],
    },
  ]}
/>

Related components

← Back to docs