Command menu
command-menuA 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.
"use client";
import { CreditCard, FileText, LayoutGrid, LifeBuoy, Search, Settings, User } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/forme/button/button";
import {
CommandMenu,
CommandMenuEmpty,
CommandMenuGroup,
CommandMenuInput,
CommandMenuItem,
CommandMenuList,
CommandMenuSeparator,
} from "@/components/forme/command-menu/command-menu";
export function CommandMenuDemo() {
const [open, setOpen] = useState(false);
const [last, setLast] = useState<string | null>(null);
// cmdk hands the item's `value` to `onSelect`, so one handler names the
// command and closes the palette, the way a native command palette does.
function run(value: string) {
setLast(value);
setOpen(false);
}
return (
<div className="flex flex-col gap-8">
<div className="flex flex-wrap items-center gap-3">
<Button variant="secondary" onClick={() => setOpen(true)}>
<Search />
Search
<kbd className="rounded border border-border bg-muted px-1.5 py-0.5 font-mono text-caption-2-regular text-muted-foreground">
⌘K
</kbd>
</Button>
<p className="text-body-regular text-muted-foreground">
{last ? (
<>
Ran <span className="text-foreground">{last}</span>
</>
) : (
"Press ⌘K, or Ctrl K on Windows and Linux."
)}
</p>
</div>
<CommandMenu label="Command menu" open={open} onOpenChange={setOpen}>
<CommandMenuInput placeholder="Type a command or search..." />
<CommandMenuList>
<CommandMenuEmpty>No commands found.</CommandMenuEmpty>
<CommandMenuGroup heading="Go to">
<CommandMenuItem
value="overview"
keywords={["home", "dashboard", "start"]}
onSelect={run}
>
<LayoutGrid />
Overview
</CommandMenuItem>
<CommandMenuItem
value="deployments"
keywords={["releases", "production"]}
onSelect={run}
>
<FileText />
Deployments
</CommandMenuItem>
<CommandMenuItem value="settings" keywords={["preferences", "config"]} onSelect={run}>
<Settings />
Settings
</CommandMenuItem>
</CommandMenuGroup>
<CommandMenuSeparator />
<CommandMenuGroup heading="Account">
<CommandMenuItem value="profile" keywords={["name", "email"]} onSelect={run}>
<User />
Profile
</CommandMenuItem>
<CommandMenuItem
value="billing"
keywords={["invoice", "plan", "payment"]}
onSelect={run}
>
<CreditCard />
Billing
</CommandMenuItem>
<CommandMenuItem value="support" keywords={["help", "contact"]} onSelect={run}>
<LifeBuoy />
Contact support
</CommandMenuItem>
</CommandMenuGroup>
</CommandMenuList>
</CommandMenu>
</div>
);
}Install
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
Dropdownis 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
| Prop | Type | Default | Description |
|---|---|---|---|
children* | ReactNode | — | |
label | string | "Command menu" | Names the palette for screen readers. |
open | boolean | — | 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
CommandMenuInputTakesComponentProps<typeof CommandInput>CommandMenuListTakesComponentProps<typeof CommandList>CommandMenuEmptyTakesComponentProps<typeof CommandEmpty>CommandMenuGroupTakesComponentProps<typeof CommandGroup>CommandMenuSeparatorTakesComponentProps<typeof CommandSeparator>CommandMenuItemTakesComponentProps<typeof CommandItem>
Accessibility
- Focus stays in the input while the arrow keys move the selection, Enter runs it and Esc closes.
labelnames 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.
Related


Breadcrumb
Where a page sits in the hierarchy, as a labelled nav with an ordered list and the current page marked. Separators are drawn in CSS, so a screen reader hears the path and not the slashes.
navigation

Dock
A macOS-style row of icons that swell under the pointer on a spring, with their neighbours growing too. Labels show on hover and focus, open apps get a dot, and reduced motion keeps every icon at its resting size.
navigation

Pagination
Page links rendered on the server, with the ends always reachable and a gap only where it hides more than one page. Previous and next hold their place on the first and last page, so nothing shifts as you click through.
navigation