Command Palette with a Search Field
A command palette opens on a shortcut, and a reader who does not know the shortcut looks for a search field. <x-wirekit:: is that field. A click on it, Enter or the Down arrow opens the palette, and so does typing: the palette opens with the text in its own field, the cursor after it.
Usage
Typing Before the Palette Is There
The field keeps the focus until the palette takes it, and every key typed in that moment lands in the field. Each one is handed to the palette again, which takes the text for as long as its own field does not have the focus, so a word typed in one go arrives whole, at any speed. Once the palette's field has the focus, the reader types there.
Text an input method is still composing goes when the composition ends: moving the focus in the middle of it would end it half-way. When the palette closes, the focus comes back to the field, and the field is empty again.
Naming the Palette
for names the palette to open, by its name. Without one the field opens every palette that answers an event without a name, which on a page with one palette is that one.
The shortcut is shown, not bound: shortcut="⌘K" puts a key hint at the end of the field, and the palette binds its own hotkey. Keep the two the same.
A screen reader does not read the hint. The field states the palette's shortcut instead, as aria-keyshortcuts, from its own hotkey prop, which defaults to the palette's default cmd+k. A palette with another hotkey wants the same value on the field:
<x-wirekit::command-palette name="search" hotkey="ctrl+shift+p" />
<x-wirekit::command-palette.trigger for="search" hotkey="ctrl+shift+p" shortcut="Ctrl+Shift+P" />
While another palette on the page has taken the shortcut, the key opens that palette and not the field's. The field then stops stating it, in aria-keyshortcuts and at its end, and states it again once that palette has left the page.
Props
The props of <x-wirekit:: are listed with the palette's own, under Props.
Accessibility
- A search field with a visually hidden label, "Search commands" by default, so the field has a name although its placeholder disappears with the first key
aria-haspopup="dialog", so a screen reader says what pressing the field opens- The shortcut hint is hidden from screen readers, and the field states the palette's shortcut as
aria-keyshortcutsinstead (Meta+K Control+Kforcmd+k, which opens the palette with either key). A shortcut another palette has taken is left out of both - Enter and the Down arrow open the palette, and the Enter that confirms an input method's conversion is left to the input method