SearchField and SearchButton
import { SearchField, SearchButton } from "@study/ui"
SearchField filters while typing, e.g. a course's files. SearchButton looks just the same but opens a search somewhere else – in the app, the command palette (⌘K).
Result
Loading...
Live Editor
function Example() { const [q, setQ] = useState(""); const files = ["Script chapter 4", "Exercise sheet 5", "Laplace formula sheet"]; return ( <div className="ui-stack" style={{ maxWidth: 420 }}> <SearchButton label="Search or create" shortcut="⌘K" onOpen={() => toast("The command palette opens here")} /> <SearchField label="Search documents" value={q} onChange={(e) => setQ(e.target.value)} onClear={() => setQ("")} /> <ul>{files.filter((f) => f.toLowerCase().includes(q.toLowerCase())).map((f) => <li key={f}>{f}</li>)}</ul> <Toaster /> </div> ); }
Variants and states
Light
Dark
When to use
✓ DoOne search per area, at the top, where people expect it.
✗ Don'tA normal TextField with a magnifier – without a role, without a clear button.
Props
| Prop | Type | Default | Meaning |
|---|---|---|---|
label * | string | – | What is searched, e.g. "Search all courses". Hidden from the eye; the placeholder shows it. |
className | string | – | |
onClear | (() => void) | – | Shows a clear button while there is text. |
ref | Ref<HTMLInputElement> | – | |
shortcut | string | – | A keyboard shortcut shown at the end, e.g. "⌘K". |
size | "md" | "lg" | md |
| Prop | Type | Default | Meaning |
|---|---|---|---|
label * | string | – | What is searched, e.g. "Search all courses". Hidden from the eye; the placeholder shows it. |
onOpen * | () => void | – | Opens the search, e.g. the command palette. |
className | string | – | |
placeholder | string | – | The text shown in the field. Default: the label with "…". |
shortcut | string | – | A keyboard shortcut shown at the end, e.g. "⌘K". |
size | "md" | "lg" | md |
Accessibility
- The field sits in a
role="search"region and has a label (hidden from the eye). - The clear button is called "Suche leeren" (clear search).
SearchButtonstates the shortcut asaria-keyshortcuts.