v22.18.0 release notes

CommandPalette

CommandPalette is a command menu opened with Ctrl+K or ⌘K: a search input above a list of commands filtered with fuzzy matching, with groups, nested pages, recent commands, async search and full keyboard support, in a modal dialog or in place.

View as .md
import { CommandPalette } from '@exhaustive-ui/core/commandpalette';

CommandPalette opens a search input above a list of commands in a modal dialog. It listens to Ctrl+K, or ⌘K on a Mac, anywhere on the page: press it now, or use the button. Typing filters the commands with fuzzy matching, the arrow keys move the active command and enter runs its command callback. visible opens and closes it, and the focus goes back to where it was when it closes.

Last command: none

An item with items is a group: its label is a heading above its commands. A command can have an icon, a description, keywords that find it without being shown, a shortcut hint rendered as keys (mod reads ⌘ on Apple devices and Ctrl elsewhere) and a disabled state. Besides command, a routerLink or a url navigates. While searching, the best matches come first, inside and across groups. A shortcut of false leaves the keyboard shortcut to the first palette of this page.

An item with children opens a page of other commands instead of running. The search starts again on the new page, with the placeholder of the item, and a breadcrumb leads back to the previous pages. backspace in the empty input goes back one page, and onPageChange follows the navigation. Pages can be nested at any depth.

Theme: System, language: English

The built-in filter matches the characters of the query in order, ignoring case and accents, in the label and the keywords; consecutive characters, word starts and exact matches rank higher, and the matched characters of the label are highlighted. A filter function replaces it: it receives an item and the query and returns false to hide the item, or a score, higher first. Here only the words that start with the query match, and a match on the label outranks one on a keyword. commandPaletteFuzzyMatch is exported to build on the built-in matching.

Go to Dashboard
Go to Orders
Go to Customers
Create Invoice
Export Report
5 results

For a server-side search, set shouldFilter to false and answer onSearch by setting items: the palette shows them as given. delay waits for a pause in typing before the event, and loading shows a spinner in the search row, and a loading message while there is no result yet. Here a fake server answers after 600 milliseconds, and the handler keeps only the latest answer.

Loading…
Loading…

With inline, the palette is rendered in place, without the dialog, in a sidebar or a launcher page for instance. Its shortcut gives the focus to its search input, and escape clears the query, then leaves the page. recent adds a group of the last commands run at the top of the root page, up to recentLimit; with recentStorageKey they are kept in the local storage between visits. Run a command to see it.

6 results

Last command: none

The item template renders an option, with the item, whether it is active, the query and the segments of the label to highlight; group renders a heading with its label and its count. The header template goes above the search input, empty replaces the empty message and footer replaces the key hints, all with the query, the page and the number of results.

People · 5
5 results

Screen Reader

The palette opens in a modal dialog labelled by the title label, with the focus trapped inside and given back to the element that had it when the palette closes. The search input follows the combobox pattern with a listbox popup, while the focus stays in the input: it has the combobox role, aria-autocomplete="list", aria-expanded while there are results, aria-controls pointing to the listbox and aria-activedescendant to the active option, which has aria-selected. Disabled commands have aria-disabled, and a command that opens a page has aria-haspopup.

Each group is a group element labelled by its heading. A polite live region announces the number of results as the query changes, the empty and loading messages, and the name of a page when it opens. The breadcrumb of the pages is a navigation landmark whose current page has aria-current="page"; its buttons are reached with the mouse, while the keyboard goes back with backspace. The key hints of the footer are hidden from screen readers, which announce the keys of their own.

Every text comes from the labels input: the title of the dialog, the inputLabel of the search input (or ariaLabel and ariaLabelledBy), the listLabel of the listbox, the resultsMessage, emptyMessage, loadingMessage and pageMessage of the live region, and the hints. The empty message defaults to the emptySearchMessage of the translation configuration.

<p-command-palette [items]="items" [labels]="{ title: 'Commandes', inputLabel: 'Rechercher une commande', resultsMessage: '{0} résultats' }" />

<span id="launcher-label">Launcher</span>
<p-command-palette inline [items]="items" ariaLabelledBy="launcher-label" />

Keyboard Support

KeyFunction
ctrl + k / ⌘ + kOpens the palette from anywhere on the page, or closes it. Another key is set with shortcut; in the inline mode it gives the focus to the search input.
down arrowActivates the next command, from the last one to the first unless loop is false. Disabled commands are skipped.
up arrowActivates the previous command, from the first one to the last unless loop is false.
home / endActivates the first or the last command.
page up / page downMoves the active command by the number of commands visible in the list.
enterRuns the active command, or opens its page.
backspaceIn the empty search input, goes back to the previous page.
escapeCloses the palette and gives the focus back. In the inline mode, clears the query, then goes back to the previous page.
tabStays in the dialog, whose only field is the search input.