Search
FreeA search field with a clear button and the right keyboard on phones.
pnpm dlx shadcn@latest add https://caliperui.site/r/search.jsonType to search.
When to use #
Use it for
- Filtering a list or directory as people type.
- Pair it with a visible result count.
Skip it when
- Global search across the app; use a command palette.
Installation #
terminal
pnpm dlx shadcn@latest add https://caliperui.site/r/search.json
Adds its 4 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage #
This is the code behind the preview above.
example.tsx
import { useState } from "react" import { Search } from "@/components/ui/search" export function DirectorySearch() { const [query, setQuery] = useState(""); return ( <div className="grid w-full max-w-xs gap-2"> <Search value={query} onChange={(event) => setQuery(event.currentTarget.value)} onClear={() => setQuery("")} placeholder="Name or role" aria-label="Search the directory" /> <p role="status" className="text-sm text-muted-foreground">{query ? `Searching for “${query}”.` : "Type to search."}</p> </div> ); }
API reference #
Search
component
Also accepts the native props of its root element and a ref.
PropTypeDefault
value *string—
onChange *ChangeEventHandler<HTMLInputElement>—
onClear *() => void—
clearLabelstring"Clear search"
Accessibility #
It is built on native elements and keeps aria-hidden and aria-label in step with state.
No custom key handling; Tab and the native activation keys do the work.
Motion #
It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.