A search trigger that looks like a field: it opens your search dialog on click or with the Ctrl + K (⌘ + K on macOS) shortcut, and shows the shortcut as a hint.
.search-triggeris abuttonthat opens the search. It looks like an input, because that's what people look for, but it isn't one: typing starts in the dialog..search-trigger__icon,.search-trigger__caption("Search") and.search-trigger__shortcut(akbdwith the hint).
- The accessible name is "Search"; the shortcut hint is hidden from screen readers (
aria-hidden="true"). When you bind the shortcut, expose it witharia-keyshortcuts="Control+K Meta+K":
<button class="search-trigger" type="button" aria-keyshortcuts="Control+K Meta+K" data-search-trigger data-shortcut>…</button>- Earlier versions used a "Ctrl K" button as the trigger, which gave it a confusing name. Now the whole control is one button with a clear name.
- The shortcut uses Ctrl/⌘ + K, a common convention that doesn't collide with typing.
The block class is
.search-trigger(it was.open-search, which is also used by many site headers).Vanilla JavaScript. The script swaps the hint to "⌘ K" on Apple devices and dispatches a
search:openevent on thedocumenton click.Add
data-shortcutto the trigger to bind the keyboard shortcut (only one per page). The demo leaves it out, because this site's own search already uses Ctrl + K. Connect it to your dialog, like the Command Palette.The control uses the form tokens (background, border, radius and focus ring), so it matches the inputs in every style.


