domestic-ui GitHub

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.

Where a search dialog is used A search dialog opens from the Search button in the app bar, over the dimmed page, with a field and its list of results.

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

KeyAction
Cmd-K / Ctrl-Kopens the dialog with focus in the field, except from a text field outside it
Typingfilters the results
Down Arrow / Up Arrowmoves to the next or previous result
Entergoes to the active result and closes the dialog
Escapecloses the list, then clears the field, then closes the dialog; focus returns to where it was
Tabmoves between the field and the close button

Accessibility

  • The browser does the modal work: showModal() or command="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-keyshortcuts on 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.

Search