SearchField
A search input with a leading icon and a clear button; Escape clears.
Signature
Density
Viewport
Theme and light/dark are set in the top barWhen to use
A search input with a leading icon and a clear button; Escape clears.
Accessibility
Always render a visible <label> (the label prop wires htmlFor/id for you). Errors set aria-invalid and are announced via aria-describedby. Required fields expose aria-required.
Install and import
npx shadcn@latest add @prism/search-field
import { SearchField } from '@/components/prism/SearchField';
In a no-build prototype, read it from the bundle instead: const { SearchField } = window.PrismDesignSystem_39d121;
Props
| Prop | Type | Required | Description |
|---|---|---|---|
label | string | — | |
value | string | — | |
defaultValue | string | — | |
placeholder | string | — | |
onChange | (value: string) => void | — | |
onClear | () => void | — | |
clearLabel | string | — | Accessible name of the clear button. Default "Clear search"; change it if the page has its own control with that name. |
isDisabled | boolean | — | |
width | "xs" | "sm" | "md" | "lg" | "full" | — | Maximum width of the box: "xs" | "sm" | "md" | "lg" (default, 36rem) | "full". Still shrinks on a phone. Sizes are the --field-width-* tokens. |
actions | React.ReactNode | — | Buttons beside the box (a Search submit, "Show all"); they wrap under it on a phone. |
onSubmit | (value: string, event: React.FormEvent<HTMLFormElement>) => void | — | Makes the bar a <form role="search">: Enter or a type="submit" button calls this (the browser's submit is prevented). |
searchLabel | string | — | Names the search landmark when the page has more than one (aria-label on the bar). |
className | string | — |