Skip to main content

Basic

A dialog with a search box and a list of pages, opened with the button or Ctrl/Cmd+K (only the layout palette, whose id is command-palette, answers the shortcut). The pages come from items, each with a text, an optional hint, an href, and an optional target, followed by the links of the page marked with data-palette-text. Typing filters by the text and the hint; the arrow keys move, Enter or a click opens the page, and an item with target="_blank" opens in a new tab. Esc or a click outside closes the dialog and the focus goes back to the button. Try typing “products”.

Empty

When nothing matches, the list says so in a role="status" block (the Empty State pattern, small) and keeps the box so the person can correct the search. This preview is a static picture (inert); the live palette above shows the same state when you type something that matches nothing.

zzz

No results for “zzz”

Check the spelling or try another word.

In a navbar

The search box of a navbar is the palette trigger. It looks like an input, but it is a button with aria-haspopup="dialog" and aria-controls pointing at the panel. The id is on the root, the button is <id>-button, and button-class adds classes to it. Another button with the same aria-controls opens the same palette, as the search icon on small screens does in the layouts.

Starkit

Options reference

The dialog opens and closes with the global dialog behaviour; command-palette.js only filters, highlights, and opens the page.

Part Value Description
label string The trigger text. Default “Search pages”.
items { text, hint, href, target }[] The pages. hint and target are optional. After them, the palette lists the links with data-palette-text (and an optional data-palette-hint), read each time it opens; a link whose href is already an item is left out. The layouts rely on the sidebar links.
button-class classes Extra classes of the trigger. Every attribute that is not a prop goes to the root.
Trigger button with aria-haspopup="dialog", aria-controls, aria-expanded Its id is <id>-button, and button-class adds classes to it. The global dialog behaviour opens and closes the panel, traps Tab, closes on Esc or a click outside, and returns the focus.
Dialog <id>-panel, aria-label The panel. It gets role="dialog" and aria-modal while it is open.
Search <id>-search, role="combobox" aria-controls the list, aria-expanded="true", aria-autocomplete="list" and aria-activedescendant with the id of the highlighted option.
List <id>-list, role="listbox" Each page is role="option" with the id <id>-option-<index> and aria-selected.
Keys Ctrl/Cmd+K, ↑ ↓, Home, End, Enter, Esc Open (layout palette only), move, jump to the first or last, open the page, close.
Empty role="status" Shown when no page matches; keeps the search box.