Search
Search is deprecated: compose a search field from TextInput instead, as in the TextInput Search example.
import { Search } from '@/components/ui/wideset/search/Search';
<Search placeholder="Search projects" aria-label="Search" />Installation
pnpm dlx wideset add search
Copies the component and any Wideset components it uses into your project.
Examples
Variants
Primary is the default. Danger marks a query your own validation rejected, such as one that is too short to run; say why next to the field, because the red border alone does not reach screen reader users.
import { Search } from '@/components/ui/wideset/search/Search';
export default function SearchVariants() {
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
{(['primary', 'danger'] as const).map((variant) => (
<Search
key={variant}
variant={variant}
placeholder="Search invoices"
aria-label="Search invoices"
/>
))}
</div>
);
}Presets
Border is the default, for a search field on the page. Ghost drops the frame until hover and focus, for a search placed inside a surface that already has one, such as a toolbar, a table header or a dropdown.
import { Search } from '@/components/ui/wideset/search/Search';
export default function SearchPresets() {
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
{(['border', 'ghost'] as const).map((preset) => (
<Search
key={preset}
preset={preset}
placeholder="Search invoices"
aria-label="Search invoices"
/>
))}
</div>
);
}Sizes
Medium is the default. Small fits filter bars and table toolbars, large a search that is the main entry point of the page. Match the size of the controls next to it.
import { Search } from '@/components/ui/wideset/search/Search';
export default function SearchSizes() {
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
{(['sm', 'md', 'lg'] as const).map((size) => (
<Search key={size} size={size} placeholder="Search invoices" aria-label="Search invoices" />
))}
</div>
);
}States
The clear button appears while the field holds a value and is enabled; clearing it returns focus to the input and calls onClear. Pass showClearButton={false} when something else resets the query. A disabled search cannot be focused, so keep it only when the user can tell why.
import { Search } from '@/components/ui/wideset/search/Search';
import { useState } from 'react';
export default function SearchStates() {
const [query, setQuery] = useState('Invoice #1042');
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
<Search placeholder="Search invoices" aria-label="Search invoices" />
<Search disabled placeholder="Search invoices" aria-label="Search invoices" />
<Search
value={query}
onChange={(event) => setQuery(event.target.value)}
placeholder="Search invoices"
aria-label="Search invoices"
/>
</div>
);
}API reference
| Name | Description | Default |
|---|---|---|
className | Layout/context overrides for the outer container. Visual styling goes through `variant`, `preset` and `size`. string | — |
clearAriaLabel | Accessible label for the clear button. Defaults to `'Clear'`. string | — |
defaultMotion | Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`. boolean | true |
onClear | Called after the value is cleared via the clear button, in both controlled and uncontrolled modes. (() => void) | — |
preset | 'border''ghost' | 'border' |
showClearButton | Renders the clear button while the input holds a value and is enabled. Defaults to `true`. boolean | true |
size | 'sm''md''lg' | — |
variant | 'primary''danger' | — |
import { Search } from '@/components/ui/wideset/search/Search';
<Search placeholder="Search projects" aria-label="Search" />