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.
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.
Each row carries a label and, when it has them, an icon, where it lives, a shortcut and a chevron for a page.
Variants and states
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. On small screens the pane hides.
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.
Usage
- 01Use it for moving around an app and running actions people would otherwise hunt for in menus.
- 02Put the commands people use most in the first group, and keep groups to a handful each.
- 03Make a command 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 the words people might type instead: appearance for Change theme, create for New file.
- 05Don't make it the only way to reach something. It speeds up people who know it's there.
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
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 Command menu. Focus goes to the search field when it opens, stays inside while it's open, and returns to the trigger when it closes.
- 02A screen reader reads each command as the highlight moves, says which group it's in, and says when a command opens a page.
- 03On a page, the search field is named after it, and the back button says where it goes.
- 04A search announces how many results it found, and the preview pane is announced as it changes.
- 05Every piece of text the menu writes can be translated.
Related components
- Filter menuA filter menu of fields and values that turns into a search as you type.
- KbdIn 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