Navigation
Command palette
A dialog with a search field over every command of an application. <kui-command-palette> opens with Ctrl+K (Cmd+K on a Mac) or a button, filters as the person types and runs the marked command with Enter.
The commands are written once, as buttons in a <template>: their text, data-command, and optional data-group, data-hint, data-keywords and data-href. Filtering ignores case and accents, so “sabac” finds “Šabac”. Running a command fires kui-command with its name, or opens its address.
Examples
Opened by a button and by Ctrl+K
Press the button, or press Ctrl+K anywhere on this page. Type “nov” or “račun”, move with the arrows, press Enter. Escape closes and focus returns to where it was.
<button class="kui-button" type="button" data-kui-open="command-palette-demo"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg><span>Search commands</span><kbd class="kui-kbd">Ctrl K</kbd></button>
<kui-command-palette id="command-palette-demo" shortcut="k">
<dialog class="kui-dialog kui-palette" aria-label="Commands">
<div class="kui-palette__search"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg><input aria-label="Search commands" autocomplete="off"></div>
<ul class="kui-listbox"></ul>
<div class="kui-palette__foot" aria-hidden="true"><span><kbd class="kui-kbd">↑</kbd> <kbd class="kui-kbd">↓</kbd> move</span><span><kbd class="kui-kbd">Enter</kbd> run</span><span><kbd class="kui-kbd">Esc</kbd> close</span></div>
<template>
<button data-command="new-case" data-group="Create" data-hint="N" data-keywords="predmet">New case</button>
<button data-command="new-invoice" data-group="Create" data-keywords="račun faktura">New invoice</button>
<button data-command="new-reminder" data-group="Create" data-keywords="podsetnik rok">New reminder</button>
<button data-command="go-cases" data-group="Go to" data-href="#command-palette-cases" data-hint="G C">Cases</button>
<button data-command="go-calendar" data-group="Go to" data-hint="G K">Calendar</button>
<button data-command="go-clients" data-group="Go to" data-keywords="klijenti">Clients in Šabac and Čačak</button>
<button data-command="theme" data-group="Settings" data-keywords="dark tamno">Switch light and dark</button>
<button data-command="lang" data-group="Settings" data-keywords="jezik ćirilica">Language: Srpski (ćirilica)</button>
</template>
</dialog>
</kui-command-palette>
States
Every state
Open: the dialog sits near the top of the window over a dimmed page, the field has focus and every command shows under its group. Typing: matches show with the typed letters underlined; the first match is marked. Nothing found: the keyed words “No results”. The marked option has a soft fill and the ring; hints sit at the end of the row.
- Create
- Novi predmetN
- Nova faktura
<div class="kui-dialog kui-palette" role="group" aria-label="The palette as it looks while open" style="display: flex; flex-direction: column; position: static; margin: 0">
<div class="kui-palette__search"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg><input aria-label="Search commands (example)" value="nov" readonly role="combobox" aria-expanded="true" aria-controls="command-palette-static" aria-activedescendant="command-palette-static-0"></div>
<ul class="kui-listbox" role="listbox" id="command-palette-static" aria-label="Commands (example)">
<li class="kui-palette__group" role="presentation">Create</li>
<li role="option" id="command-palette-static-0" aria-selected="false" data-active><span><mark>Nov</mark>i predmet</span><span class="kui-palette__hint">N</span></li>
<li role="option" id="command-palette-static-1" aria-selected="false"><span><mark>Nov</mark>a faktura</span></li>
</ul>
<div class="kui-palette__foot"><span>2 results</span></div>
</div>
Classes and attributes
kui-command-palette- The element: a kui-dialog with a search over commands. Give it an id for data-kui-open.
shortcut- The letter that opens it with Ctrl or Cmd; k by default.
dialog.kui-dialog.kui-palette- The dialog; give it an aria-label.
.kui-palette__search- The row with the search icon and the input; give the input an aria-label.
ul.kui-listbox- The list the element fills with the matching commands.
template > button[data-command]- One command: its text is its name. data-group, data-hint, data-keywords, data-href.
.kui-palette__foot- A row of key hints under the list.
data-kui-open="ID"- On any button: opens the palette.
kui-command- Event when a command runs; detail.command is its data-command.
Keyboard
- Ctrl + K
- Opens or closes the palette from anywhere on the page (Cmd+K on a Mac).
- Arrow Down or Arrow Up
- Moves the mark through the commands.
- Enter
- Runs the marked command and closes the palette.
- Escape
- Closes the palette; focus returns to where it was.
Accessibility
- The dialog is a native modal dialog: focus stays inside and the page behind is inert.
- The field is a combobox that controls the list (role="listbox"); the marked option is its aria-activedescendant, so focus stays in the field while the arrows move.
- Group names are presentational rows; each option’s name is its command.
- Every command in the palette is also reachable some other way; the palette is a shortcut, not the only path.
- The shortcut is shown on the opening button, so people who do not know it can learn it.
Do and do not
Do
- Name commands with a verb first: “New invoice”, “Go to calendar”.
- Add keywords in the languages your people use.
- Keep one palette per page.
Do not
- Do not take over Ctrl+K inside a text editor that uses it for links; pick another letter.
- Do not put destructive commands in the palette without asking for confirmation.
- Do not fill the palette with every setting; keep it to what people do often.