Forms
SearchInput
Free16.2 KB gzippedA search field built on Input: type="search", a search icon, a clear button, and pill rounding by default. Fires onSearch on Enter and, optionally, after a typing pause (debounce). Escape clears the field. An optional global shortcut (e.g. Cmd/Ctrl+K) focuses it, and resultsCount announces result counts politely.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Ctrl+K, /, Enter and 1 more · Full report
Import
import { SearchInput, SearchForm } from "@vjdesigns/vjdesigns-ui";
Importing only SearchInput adds about 16.2 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Live filter
debounce runs the search after typing pauses, and resultsCount announces the result count to screen readers.
10 results
- Apple
- Apricot
- Banana
- Blueberry
import { useMemo, useState } from "react";
import { List, SearchInput, Stack, Text } from "@vjdesigns/vjdesigns-ui";
const fruits = ["Apple", "Apricot", "Banana", "Blueberry", "Cherry", "Grape", "Mango", "Peach", "Pear", "Plum"];
export function LiveFilter() {
const [query, setQuery] = useState("");
const results = useMemo(
() => fruits.filter((fruit) => fruit.toLowerCase().includes(query.toLowerCase())),
[query],
);
return (
<Stack gap={4} style={{ width: "100%", maxWidth: "22rem" }}>
<SearchInput aria-label="Search fruit" placeholder="Search fruit" debounce={200} onSearch={setQuery} resultsCount={results.length} />
<Text size="sm" tone="muted">
{results.length} results
</Text>
<List variant="divided" size="sm">
{results.slice(0, 4).map((fruit) => (
<List.Item key={fruit}>{fruit}</List.Item>
))}
</List>
</Stack>
);
}
Site search
Wrap it in SearchForm for a search landmark. shortcut adds a global key that focuses the field.
Press / to focus the field, then Enter to search.
import { useState } from "react";
import { SearchForm, SearchInput, Stack, Text } from "@vjdesigns/vjdesigns-ui";
export function SiteSearch() {
const [submitted, setSubmitted] = useState("");
return (
<Stack gap={3} style={{ width: "100%", maxWidth: "26rem" }}>
<SearchForm aria-label="Site search" onSearch={setSubmitted}>
<SearchInput aria-label="Search the site" placeholder="Search the site" shortcut={["/"]} />
</SearchForm>
<Text size="sm" tone="muted">
{submitted ? `You searched for “${submitted}”.` : "Press / to focus the field, then Enter to search."}
</Text>
</Stack>
);
}
Accessibility
Pass resultsCount and the number of results is announced politely once it settles, without moving focus, so screen reader users know the list changed. shortcut={["/"]} focuses the field from anywhere and sets aria-keyshortcuts.
Apple, Apricot, Banana, Blueberry, Cherry, Grape, Mango, Peach, Pear, Plum
import { useState } from "react";
import { SearchInput, Stack, Text, Field } from "@vjdesigns/vjdesigns-ui";
const fruits = ["Apple", "Apricot", "Banana", "Blueberry", "Cherry", "Grape", "Mango", "Peach", "Pear", "Plum"];
export function Accessibility() {
const [query, setQuery] = useState("");
const matches = fruits.filter((fruit) => fruit.toLowerCase().includes(query.trim().toLowerCase()));
return (
<Stack gap={3} style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Filter fruit">
<SearchInput value={query} onValueChange={setQuery} resultsCount={matches.length} shortcut={["/"]} clearable fullWidth />
</Field>
<Text size="sm" tone="muted">
{matches.join(", ") || "No matches"}
</Text>
</Stack>
);
}
Translated
The results announcement ("5 resultados"), the clear button's name and the shortcut hint come from the locale (Spanish here).
import { SearchInput, Field, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import es from "@vjdesigns/vjdesigns-ui/locales/es";
export function Translated() {
return (
<LocaleProvider locale="es" messages={es}>
<div style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Buscar">
<SearchInput defaultValue="camiseta" resultsCount={5} clearable fullWidth />
</Field>
</div>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Live filter
10 results
- Apple
- Apricot
- Banana
- Blueberry
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// LiveFilter is the "Live filter" example above.
<LocaleProvider locale="ar" messages={ar}>
<LiveFilter />
</LocaleProvider>
Usage notes
Accessible name: label it with a Field, a <label htmlFor>, aria-label, or aria-labelledby. If none of these is present, aria-label="Search" is applied as a fallback. The placeholder is never used as the name.
Landmark: wrap it in SearchForm to get a <form role="search"> landmark; Enter then submits the form, which calls both callbacks.
<SearchInput aria-label="Search players" debounce={300} onSearch={runSearch} shortcut={["mod", "k"]} />
API reference
SearchInput
| Prop | Type | Default |
|---|---|---|
valueControlled query. Pair with | string | — |
defaultValueInitial query when uncontrolled. | string | "" |
onValueChangeCalled with the new query on every edit (typing, pasting, clearing). Fires immediately, never debounced. | (value: string) => void | — |
onSearchCalled with the query when a search should run:
| (query: string) => void | — |
debounceMilliseconds of idle typing before | number | — |
minLengthMinimum trimmed length before a *debounced* search fires. Enter always searches. Not forwarded as the native | number | 0 |
onClearCalled after the user clears the field with the clear button or Escape. | () => void | — |
clearableShows a clear button while the field has a value. | boolean | true |
clearLabelAccessible name of the clear button. | string | "Clear search" |
blurOnEscapeWhen Escape is pressed in an already-empty field, blur it. The Escape event always bubbles in that case (so a surrounding dialog can close); when the field has a value, Escape only clears it and stops there. | boolean | true |
shortcutA global keyboard chord that focuses the field, e.g. | SearchShortcutKey[] | — |
shortcutEnabledTurns the global | boolean | true |
shortcutPlatformForce the platform used for the shortcut hint and | "mac""windows""linux" | — |
resultsCountNumber of results for the current query. When set, a polite live region announces | number | — |
resultsLabelBuilds the results announcement. | (count: number) => string | "No results" / "1 result" / "N results" |
announceDelayQuiet period (ms) before announcing | number | 700 |
radiusCorner rounding. | "sm""md""lg""none""xs""xl""2xl""pill" | "pill" |
refRef to the | Ref<HTMLInputElement> | — |
startIconDecorative icon before the text. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon after the text. Hidden from assistive technology. | ReactNode | — |
loadingShows a decorative spinner at the end and sets | boolean | false |
fullWidthStretches the field to fill its container. | boolean | true |
variantVisual style. | "outline""filled" | "outline" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
invalidMarks the value as invalid: sets | boolean | false |
inputClassNameClass name for the | string | — |
startAddonStatic content attached to the start edge, such as | ReactNode | — |
endAddonStatic content attached to the end edge, such as | ReactNode | — |
startElementInteractive content inside the start edge (for example an | ReactNode | — |
endElementInteractive content inside the end edge (for example a copy or show-password | ReactNode | — |
htmlSizeThe native | number | — |
Also accepts standard HTML attributes, plus className, style and ref.
SearchForm
A <form role="search"> landmark around a SearchInput, so screen reader users can jump straight to search. Give it an accessible name, especially when a page has more than one search landmark. Submitting prevents the page navigation and calls both the form's onSearch and the input's onSearch with the current query. Use one SearchInput per SearchForm.
| Prop | Type | Default |
|---|---|---|
childrenThe SearchInput plus any filters or a submit button. | ReactNode | — |
aria-labelAccessible name of the search landmark, e.g. "Site search". | string | — |
aria-labelledbyid of a visible heading or label naming the landmark. | string | — |
onSearchCalled on submit (Enter in the SearchInput, or a submit button) with the SearchInput's query. The native submit is always prevented. | (query: string, event: FormSubmitEvent) => void | — |
Also accepts native <form> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
SearchInput targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Ctrl+K/ | With shortcut: focuses the field from anywhere on the page. |
| Enter | Runs the search. |
| Escape | Clears the text; with blurOnEscape, a second press leaves the field. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
<input type="search"> | searchbox | aria-keyshortcuts when there's a shortcut |
SearchForm | search | A <form> landmark |
| Result count | status | Announced politely |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |