Search Input
ProNewA search field with a clear button, a debounced callback, a loading state and a focus shortcut.
Installation
pnpm dlx shadcn@latest add @viewport/search-input
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| value | string | — |
| defaultValue | string | "" |
| onSearch | (query: string) => voidRuns once typing pauses, and immediately when the field is cleared. | — |
| debounce | numberMilliseconds of quiet before `onSearch` runs. | 250 |
| loading | booleanReplaces the search icon with a spinner while results load. | false |
| shortcut | stringA single key that focuses the field from anywhere on the page, e.g. "/". Shown as a hint while the field is empty. | — |
Accessibility
- A native search input with an accessible name.
- Escape clears the field first, then lets the key through to a surrounding dialog.
- The shortcut is ignored while you type in another field.
- Respects prefers-reduced-motion.