Skip to main content

Command palette

The ⌘K palette: navigation, commands and live catalogue search.

Guidance​

The command palette is the keyboard entry point to everything in the catalog. It mixes page navigation and actions (commands, filtered locally with a prefix, then word-start, then substring scorer that also matches keyword synonyms) with live catalogue results (search, debounced 120ms, stale calls aborted). It opens and closes instantly: the guidelines bans animated command palettes, so the dialog has no transition at all.

Scope the search with Tab (All, Assets, Glossary, Teams, Pages) or the chips under the input, and type > to see commands only. With an empty query it shows recents, then every command.

Every row shows its own shortcut as a keycap when it has one, and the active row also shows the Enter keycap, so the key that will act is always on screen. Rows without a shortcut show only the Enter keycap when active.

Built as a modal <dialog> containing an ARIA combobox (the input, with aria-activedescendant) that controls a grouped listbox, following https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-autocomplete-list/. Keys: ArrowDown and ArrowUp move and wrap, Home and End jump to the first and last result, PageDown and PageUp move by ten, Enter opens the active row, Tab and Shift+Tab change scope, Escape closes and returns focus to where it was. Set global-shortcut to toggle with ⌘K or Ctrl+K anywhere.

Selecting a row fires mm-select; unless that is cancelled, the palette then calls the command's run() or navigates to its href. It always closes.

With search-href (such as /discover?q={query}), every typed query ends with a "Search the catalog for …" row that opens the full search page, so people can always get from the palette to every result, including when nothing matched. It fires mm-search-all; cancel it to route in a single-page app.

Properties​

PropertyAttributeTypeDefaultDescription
openopenbooleanfalseOpens the palette as a modal dialog.
inlineinlinebooleanfalseRenders the panel in place instead of as a modal, for documentation and embedded launchers.
commandsPaletteCommand[][]Static navigation and actions, filtered locally. Filter by permission before passing them in.
recentsPaletteItem[][]Shown above the commands when the query is empty.
searchPaletteSearch | undefinedLive catalogue search. Called 120ms after typing stops; the signal aborts when a newer query starts.
queryquerystring''The search text, without the > prefix.
scopescopePaletteScope'all'all (default), assets, glossary, teams, pages or commands (the > prefix).
placeholderplaceholderstring''
searchHrefsearch-hrefstring''The full search page, with {query} where the encoded query goes, e.g. /discover?q={query}. Adds a "Search the catalog for …" row to every query.
globalShortcutglobal-shortcutbooleanfalseToggle with ⌘K on Apple platforms and Ctrl+K elsewhere, from anywhere on the page.
slashShortcutslash-shortcutbooleanfalseAlso open with "/" when focus is not in a text field.

Methods​

MethodDescription
show()Opens the palette and focuses the input.
hide()Closes the palette and returns focus to where it was.

Events​

EventDetailDescription
mm-selectCustomEvent<MmPaletteSelectDetail>When a row is chosen. Cancel it to handle href or run yourself.
mm-openCustomEvent<null>When the palette opens.
mm-closeCustomEvent<null>When the palette closes.
mm-queryCustomEvent<MmPaletteQueryDetail>When the query or scope changes.
mm-search-allCustomEvent<MmPaletteSearchAllDetail>When "Search the catalog for …" is chosen. Cancel it to route yourself.

CSS parts​

PartDescription
panelThe dialog panel (mm-raised, radius-lg, shadow-dialog).
inputThe native input (role combobox).
scopesThe scope chip row.
listboxThe scrolling listbox.
optionEach option row.
footerThe navigation hints on mm-sunken.

Examples​

Every state of mm-command-palette in Storybook, with keyboard and screen reader tests.