Search dialog
A command palette: a modal <dialog> holding a combobox of pages and sections, opened from a Search button or with Cmd-K or Ctrl-K.
Live example
Search dialog
<button type="button" commandfor="site-search" command="show-modal" aria-haspopup="dialog" aria-keyshortcuts="Control+K Meta+K" hidden>Search</button>
<dialog id="site-search" data-dialog closedby="any" aria-labelledby="site-search-title">
<header>
<h2 id="site-search-title">Search</h2>
<button type="button" commandfor="site-search" command="close" data-button="quiet">Close</button>
</header>
<dui-combobox>
<label for="site-search-input">Search the docs</label>
<input type="text" id="site-search-input" list="site-search-options" autocomplete="off" spellcheck="false" autofocus>
<datalist id="site-search-options">
<option value="Button" label="Atoms"></option>
<option value="Field" label="Atoms"></option>
<option value="Dialog and drawer" label="Organisms"></option>
<option value="Tabs" label="Molecules"></option>
<option value="Button › Attributes" label="Atoms"></option>
<option value="Dialog and drawer › Modal dialog" label="Organisms"></option>
<option value="Dialog and drawer › Drawer (end)" label="Organisms"></option>
<option value="Tabs › Keyboard" label="Molecules"></option>
</datalist>
</dui-combobox>
</dialog>
<p role="status" id="site-search-result"></p>
Attributes
Keyboard
| Key | Action |
|---|---|
| Cmd-K / Ctrl-K | opens the dialog with focus in the field, except from a text field outside it |
| Typing | filters the results |
| Down Arrow / Up Arrow | moves to the next or previous result |
| Enter | goes to the active result and closes the dialog |
| Escape | closes the list, then clears the field, then closes the dialog; focus returns to where it was |
| Tab | moves between the field and the close button |
Accessibility
- The browser does the modal work:
showModal()orcommand="show-modal"makes the page inert, moves focus to the field (autofocus) and returns it to the opener or wherever it was on close (APG Dialog (Modal)). - The dialog is named by its heading. The field has a visible label (WCAG 3.3.2).
- Results are combobox options: focus stays in the field, arrow keys move the active result, and the count is announced after typing pauses (WCAG 4.1.3).
- The shortcut needs a modifier, so it never fires while typing (WCAG 2.1.4).
aria-keyshortcutson the opener exposes it. - A result on the same page moves focus to its heading (WCAG 2.4.3).
- The opener stays hidden until the script that fills the results runs, so nothing broken shows without JavaScript.
- Why it is built this way, and the choices that are ours: the search dialog explainer.
Specifications
See also
How other systems do it
For comparison only; these are not the standard this system follows.