Skip to content
Browse docs and components

Command menu

command-menu

A command palette opened with ⌘K or Ctrl K, with a search field, grouped items, keyword matching and an empty state. Built on cmdk for the filtering and the keyboard path, inside a Radix dialog for the focus trap.

Responsive

Install

$npxshadcnadd@forme/command-menu

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import {
  CommandMenu, CommandMenuEmpty, CommandMenuGroup, CommandMenuInput, CommandMenuItem, CommandMenuList,
} from "@/components/forme/command-menu/command-menu";

<CommandMenu open={open} onOpenChange={setOpen}>
  <CommandMenuInput placeholder="Search…" />
  <CommandMenuList>
    <CommandMenuEmpty>Nothing found.</CommandMenuEmpty>
    <CommandMenuGroup heading="Projects">
      <CommandMenuItem onSelect={() => go("/forme-web")}>forme-web</CommandMenuItem>
    </CommandMenuGroup>
  </CommandMenuList>
</CommandMenu>

When to use

Reach for it

  • Jumping anywhere and running any command from the keyboard, opened with ⌘K or Ctrl K.

Use something else

  • A handful of actions on one object; a Dropdown is closer to hand.
  • The only way to reach something. Everything in the palette should also be reachable without it.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

CommandMenu

PropTypeDefaultDescription
children*ReactNode—
labelstring"Command menu"Names the palette for screen readers.
openboolean—Pass these when the items need to close the palette on select. Left out, the menu keeps its own state and closes on Esc or a click outside.
onOpenChange(open: boolean) => void—

The other parts

  • CommandMenuInputTakes ComponentProps<typeof CommandInput>
  • CommandMenuListTakes ComponentProps<typeof CommandList>
  • CommandMenuEmptyTakes ComponentProps<typeof CommandEmpty>
  • CommandMenuGroupTakes ComponentProps<typeof CommandGroup>
  • CommandMenuSeparatorTakes ComponentProps<typeof CommandSeparator>
  • CommandMenuItemTakes ComponentProps<typeof CommandItem>

Accessibility

  • Focus stays in the input while the arrow keys move the selection, Enter runs it and Esc closes.
  • label names the palette for screen readers.

Motion

  • None, on purpose: something summoned from the keyboard many times a day is there on the frame the key lands.