Search bar
A search field for the sidebar or a toolbar, with ⌘K to focus it from anywhere.
Installation
npm i @uisatin/uiimport { SearchBar } from '@uisatin/ui/search-bar'About 15.6 kB of JavaScript, minified and gzipped, with what it imports (React aside). The stylesheet is one file for every component.
npx shadcn@latest add https://uisatin.dev/r/search-bar.jsonAdds search-bar.tsx, command-menu.tsx, dropdown.tsx, kbd.tsx, labels.tsx and pointer-modality.tsx to components/ui and installs iconoir-react.
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
The SearchBar component is a wrapper around the input element of type search, with a search icon and the ⌘K keys. ⌘K or Ctrl+K anywhere on the page focuses it and Escape clears it. variant="panel" shows the results in place: groups filtered as you type, the arrows to move, Enter to open, a footer of key hints and meta.
| Prop | Type | Default |
|---|---|---|
variant | "field""panel" | "field" |
shortcut | boolean | variant === "field" |
hotkey | boolean | shortcut |
placeholder | string | "Search…" |
groups | CommandGroup[] | — |
idleText | ReactNode | — |
emptyText | (query: string) => ReactNode | — |
meta | ReactNode | — |
hints | boolean | true |
wrapperClassName | string | — |
className | string | — |
ref | Ref<HTMLInputElement> | — |
...props | ComponentProps<'input'>Other attributes go to <input> | — |
Accessibility
A native input of type search (searchbox) named "Search" (searchField in SatinLabels) unless you pass aria-label ("Search docs"); the icon and keycaps are hidden. In the panel the input is a combobox that controls the results listbox; the highlighted row is its aria-activedescendant, so focus stays in the field.
| Key | Action |
|---|---|
| ⌘KorCtrl+K | Focuses the field and selects its text, from anywhere on the page, unless hotkey is off. |
| ↑or↓ | Panel: moves the highlight through the results, wrapping at the ends. |
| Enter | Panel: opens the highlighted result (its onSelect). |
| Esc | Clears the field when it has text. |
Something wrong or missing on this page?
Report a problemSuggest an improvement