Command menu
A Cmd+K palette for moving around an app and running actions. Commands can open pages of their own, the ones you ran last come first, a search ranks every command across every page, and a side pane previews the highlighted one.
Examples
Views
The menu has three views, and a few states within them.
With a preview
When anything on screen has a preview, the dialog widens and a pane follows the highlight. Commands without one show No preview. When the dialog itself is narrower than 36rem, the pane hides, so it also stays hidden in a small container on a wide screen.
Inset
variant="inset" sets the list in a card inside a muted shell. The search box
and the keyboard hints sit on the shell, with no rules between them, so the
results read as a layer of their own.
Rows
Each row can carry an icon, a shortcut and a chevron for a page. Recent commands and search results also name where they live, and a disabled row fades.
In a header
The usual home: a search field in the app's header, where people look for search.
Your own trigger
Any button can open it in place of the search field.
Opened from anywhere
With no trigger, the app decides when it opens, from a button, a menu item or the shortcut.
Last command: none
Inside a card
modal={false} opens the menu without trapping focus, locking the page's
scroll or moving focus into it, and opening a page leaves focus where it is.
Use it for a menu shown inside a card or a cover rather than over the page.
Anatomy
The dialog is three regions stacked over a backdrop: the search field, the list of commands with an optional preview pane beside it, and the keyboard hints.
- Search field
- Group label
- Item
- Keyboard hints
- Backdrop
- Preview pane
Each row carries a label and, when it has them, an icon, where it lives, a shortcut and a chevron for a page.
- Group label
- Highlighted row
- Icon
- Disabled row
- Context
- Shortcut
- Page
Guidelines
- 01Use it for moving around an app and running actions people would otherwise hunt for in menus.
- 02Start labels with a verb for actions (New file, Change theme) and use the plain name for places and things (Inbox, Roadmap 2027).
- 03Make an item a page when it needs a choice before it can run: a theme, a person, a status. Keep pages one or two levels deep.
- 04Add keywords for the words people might type instead: appearance for Change theme, create for New file.
- 05Give previews to things people pick between by content, such as files and people. Leave them off plain actions.
- 06Don't make it the only way to reach something. It speeds up people who know it's there.
Best practices
Accessibility
Everything works from the keyboard, and the keys are the ones people know from other palettes.
| Key | Does |
|---|---|
| ⌘K or CtrlK | DoesOpens and closes the menu from anywhere on the page |
| ↑↓ | DoesMoves the highlight |
| ↵ | DoesRuns the highlighted command, or opens its page |
| ⌫ | DoesOn an empty search, steps back out of a page |
| Esc | DoesClears the search, then leaves the page, then closes |
- 01It's a modal dialog named by label. Focus moves to the search box when it opens, stays inside while it's open, and returns to the trigger when it closes.
- 02With
modalset tofalseit doesn't trap or move focus, so keep it for a menu that's part of the page, such as a demo in a card, where people choose to reach into it. - 03The search box is a combobox that points at the highlighted command with aria-activedescendant, so screen readers read each one as the arrows move.
- 04On a page, the search box is named after it, such as Command menu, Change theme, and the back button says where it goes. Items that open a page say so.
- 05Escape steps back one level at a time: it clears the search, then leaves the page, then closes the menu without running anything.
- 06A search announces how many results it found, and the preview pane is a polite live region.
- 07The keyboard hints are hidden from screen readers, which announce the combobox's keys themselves.
- 08Every piece of text the menu writes can be translated with
labels, alongsideplaceholder,emptyTextandlabel.
Related components
- Filter menuA filter menu of fields and values that turns into a search as you type.
- KbdIn fibo's Storybook
- AvatarIn fibo's Storybook
References
- Base UI Dialog, for the modal
- Base UI Autocomplete, for the search and list
- WAI-ARIA combobox pattern
- Motion for React, for the page slides