Browse the docs

SearchField & CommandPalette

A search box with a wobbly marker outline that boils while it has focus, grouped results on a taped sheet, highlighter matches and keycap shortcuts. The same field powers a ⌘K command palette.

Client componentWCAG AANew

Live example

Change every prop live in the playground.

Props

SearchField

PropTypeDefaultWhat it does
labelrequiredstringnoneWhat you're searching, e.g. "Search components". Always read by screen readers.
classNamestringnoneExtra class on the outer wrapper.
defaultValuestring""Uncontrolled initial text.
emptyGroupsSearchGroup[]noneShown when the box is empty and focused, e.g. quick actions. Recent searches come first.
filterbooleantrueFilter groups by the typed text and cap each at limit. false shows groups as given.
focusOnMountbooleanfalseFocus the input as soon as it mounts (the palette does this when it opens).
groupsSearchGroup[]noneWhat can be found. Filtered as you type (title, sub, meta and keywords); pass filter={false} if you filter yourself, e.g. on a server.
hideLabelbooleanfalseHide the label visually (it stays for screen readers). Use it in tight headers.
inlinebooleanfalseKeeps the results sheet open inline and the text after a pick; the command palette uses it.
limitnumber4Max results per group.
loadingbooleanfalseHop dots instead of the eraser while results load.
onSelect(item: SearchItem, group: SearchGroup) => voidnonePicked with Enter or a click.
onValueChange(value: string) => voidnoneCalled with the new text as you type, and with "" when the box is cleared or a result is picked.
placeholderstringthe labelHint text in the empty box.
recentKeystringnoneRemember picks under this localStorage key and offer them as recent searches.
shortcutstringnoneA keycap hint, and the key that focuses the field from anywhere on the page. "/" is a good one.
size"sm" | "md" | "lg"nonesm for headers, md (default), lg for a page about finding things.
valuestringnoneControlled text in the box.

CommandPalette

PropTypeDefaultWhat it does
groupsrequiredSearchGroup[]noneWhat can be found while typing.
onSelectrequired(item: SearchItem, group: SearchGroup) => voidnoneCalled with the picked item and its group, after the palette closes.
emptyGroupsSearchGroup[]noneShown before typing, e.g. quick actions.
labelstring"Type a command or search"Accessible name of the dialog and its search field.
onOpenChange(open: boolean) => voidnoneCalled with the new open state when the shortcut, Escape, the backdrop or a pick opens or closes it.
openbooleanfalseControlled open state. Leave both out and the palette opens with the shortcut on its own.
placeholderstringthe labelHint text in the empty box.
recentKeystringnoneRemember picks under this localStorage key and offer them as recent searches.
shortcutbooleantrueToggle with Cmd+K on a Mac, Ctrl+K elsewhere.

Use it well

DoGroup results by kind and give each a lead (a face, a status dot, an icon) so people can scan without reading.
Don'tHide the only way to reach a page inside the palette. It's a shortcut, not the map.

Accessibility

  • The input is a combobox: aria-expanded, aria-controls and aria-activedescendant follow the arrow keys.
  • Enter opens the active (or first) result; Escape clears the text, then closes.
  • The result count is announced in a polite live region; group headings are never focusable.
  • The palette is a native <dialog>, so focus stays inside and Escape closes it.
Five stamps!

All aboard.

You took the whole tour. Here's Holo Pip, a foil sticker for riders who finish. It's in your playground tray now, for good.