Skip to content

Search Dialog

A quick search: search by keyword and pick from a list, in a modal (the pattern is also marketed as “command palette”, but nothing here is a command). It composes the Dialog (native <dialog> element, scroll lock, Escape / backdrop close, focus restore) and the Combobox (search, filter, keyboard) — no new core code. What it searches is up to the application: content, pages, files, people, or the service’s own actions and features.

Give items a group (“Pages”, “Actions”) to section the results by type under a header, like a product-wide quick search: ungrouped results come first, groups follow in order of first appearance, and a group whose results are all filtered out disappears with its header. Keyboard traversal is flat — arrows cross group boundaries in display order.

suggestions are shown while the query is empty — recents, frequent searches: the application measures and decides, the dialog displays (they may carry their own group, e.g. “Recent”). Set loading while results are fetched: an indicator appears, the status region announces “Searching…”, and the empty state waits; feed the async results through items when they arrive.

Items can carry a shortcut (“⌘S” or ["⌘", "S"] for a chord), rendered right-aligned as a keycap. It is a label, not a binding: the dialog never registers keyboard shortcuts — live shortcuts belong to the application, like the one that opens it. No open shortcut is built in either: bind open and wire it in the application (the demo above uses ⌘S / Ctrl+S).

Unlike the family’s simple dialogs, it asks nothing and interrupts nothing — it is a search tool inside the same modal shell.

  • Dialog — generic modal for any content; the head of the family.
  • Alert Dialog — an acknowledgement: a message with nothing to cancel (one button).
  • Confirm Dialog — verify or accept before proceeding: cancel stops, confirm proceeds (urgent to interrupt).
  • Prompt Dialog — asks for a single value (optional, required, or gated by confirmValue; urgent to interrupt).
  • Search Dialog — a quick search: search by keyword and pick from a list.
  • Sheet Dialog — a task in an edge-anchored panel (side variant, optional drag-to-dismiss).
<script>
import SearchDialog from "@invisible-ui/svelte/SearchDialog.svelte";
</script>

In Elements, assign the results as a property and listen for select:

<ds-search-dialog trigger="Search…" placeholder="Search pages and actions"></ds-search-dialog>
<script type="module">
const search = document.querySelector("ds-search-dialog");
search.items = [
{ value: "home", label: "Home", group: "Pages" },
{ value: "save", label: "Save", group: "Actions", shortcut: ["⌘", "S"] },
];
search.suggestions = [{ value: "home", label: "Home", group: "Recent" }];
search.addEventListener("select", (event) => run(event.detail.value));
</script>

The title names the dialog and stays visually hidden: hide-title="false" shows it, and close-button adds a close button to the header.

In React, pass the results as items and read the choice in onSelect. useSearchDialog gives the same behaviour for markup of your own:

<SearchDialog
items={[
{ value: "home", label: "Home", group: "Pages" },
{ value: "save", label: "Save", group: "Actions", shortcut: ["⌘", "S"] },
]}
suggestions={[{ value: "home", label: "Home", group: "Recent" }]}
onSelect={(value) => run(value)}
/>
PropTypeDefaultDescription
triggerVariant"default" | "primary" | "secondary" | "ghost" | "danger""default"Visual variant for the trigger Button.
items *SearchDialogItem[]—
suggestionsSearchDialogItem[][]Items shown while the query is empty — recents, frequent searches. The application measures and decides; the dialog displays. They may carry their own group ("Recent"). Empty means: an empty query shows all items.
loadingbooleanfalseResults are being fetched: shows an indicator, announces "Searching…" through the status region and suppresses the empty state meanwhile. Feed async results through items when they arrive.
openbooleanfalse
titlestring | undefinedundefinedAccessible title for the dialog. Defaults to the i18n catalog's "Search".
hideTitlebooleantrueVisually hide the title (the default: the search field reads as the header). It still names the dialog for screen readers.
closeButtonbooleanfalseShow a close button in the header; it closes like Escape.
closeLabelstring | undefinedundefinedAccessible label for the close button. Defaults to the i18n catalog's "Close".
labelstring | undefinedundefinedAccessible label for the search input. Defaults to the i18n catalog's "Search".
placeholderstring | undefinedundefinedInput placeholder. Defaults to the i18n catalog's "Type to search…".
emptyTextstring | undefinedundefinedText shown when nothing matches. Defaults to the i18n catalog's "No results found.".
onSelect((value: string) => void) | undefinedundefined
onOpenChange((o: boolean) => void) | undefinedundefined
triggerSnippet | undefinedundefinedThe trigger button's content. Defaults to the i18n catalog's label.

The trigger snippet is the opener button’s content.

  • A modal role="dialog" (aria-modal) containing a role="combobox" search input over a role="listbox" of results. On open, focus moves to the input and is trapped; Escape / a backdrop press close it and restore focus.
  • Typing filters; Arrow Up/Down move the highlight (aria-activedescendant), Enter selects the active result and closes.
  • The query is what the user wrote, so focus leaving the input changes nothing: the text stays and the palette stays open. Dismissal belongs to the dialog (Escape, a backdrop press), not to focus. This is the opposite of the Combobox, whose text is a filter over a value it must go back to.
  • Grouped results sit in role="group" containers named via aria-label, so screen readers announce the section when entering it; the visible header is hidden from AT to avoid double reading.
  • A visually-hidden role="status" region announces the filtered result count (“3 results available” / “No results found.”) on every keystroke — and “Searching…” while loading — so screen-reader users hear the effect of their typing.
  • Item shortcuts are rendered with the semantic <kbd> element (via the Kbd component) and are part of the option’s accessible name.
<script>
let open = $state(false);
const items = [
{ value: "home", label: "Home", group: "Pages" },
{ value: "new", label: "New File", group: "Actions" },
{ value: "save", label: "Save", group: "Actions" },
];
</script>
<svelte:window
onkeydown={(e) => {
if ((e.metaKey || e.ctrlKey) && e.key === "s") {
e.preventDefault();
open = true;
}
}}
/>
<SearchDialog {items} bind:open onSelect={(value) => run(value)}>
{#snippet trigger()}<span>Search…</span>{/snippet}
</SearchDialog>

Themeable via --ds-search-dialog-* (panel width, inset, radius) plus the shared --ds-dialog-* overlay tokens.