Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

SearchInput

Free16.2 KB gzipped

A 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

tsx
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
tsx
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>
  );
}

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.

tsx
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

tsx
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).

tsx
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
tsx
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.

tsx
<SearchInput aria-label="Search players" debounce={300} onSearch={runSearch} shortcut={["mod", "k"]} />

API reference

SearchInput

SearchInput props
PropTypeDefault
value

Controlled query. Pair with onValueChange.

string—
defaultValue

Initial query when uncontrolled.

string""
onValueChange

Called with the new query on every edit (typing, pasting, clearing). Fires immediately, never debounced.

(value: string) => void—
onSearch

Called with the query when a search should run:

  • on Enter (always, even for an empty or short query; inside a plain <form> this replaces the native submit, so use SearchForm to submit),
  • when debounce is set, after typing pauses for that many ms,
  • on submit of a surrounding SearchForm.
(query: string) => void—
debounce

Milliseconds of idle typing before onSearch fires automatically. Leave unset to search only on Enter. When set, emptying the field fires onSearch("") immediately so results can reset, and a query identical to the last debounced one is not re-sent.

number—
minLength

Minimum trimmed length before a *debounced* search fires. Enter always searches. Not forwarded as the native minlength attribute.

number0
onClear

Called after the user clears the field with the clear button or Escape.

() => void—
clearable

Shows a clear button while the field has a value.

booleantrue
clearLabel

Accessible name of the clear button.

string"Clear search"
blurOnEscape

When 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.

booleantrue
shortcut

A global keyboard chord that focuses the field, e.g. ["mod", "k"] (Cmd+K on Mac, Ctrl+K elsewhere) or ["/"]. Shows a key hint at the end while the field is empty and unfocused, and sets aria-keyshortcuts. Ignored while the user is typing in another text field.

SearchShortcutKey[]—
shortcutEnabled

Turns the global shortcut listener (and hint) on or off.

booleantrue
shortcutPlatform

Force the platform used for the shortcut hint and mod matching. Detected by default.

"mac""windows""linux"—
resultsCount

Number of results for the current query. When set, a polite live region announces resultsLabel(resultsCount) after the user searches or edits, once the count has been stable for announceDelay ms and loading is false. Nothing is announced before the first edit or search.

number—
resultsLabel

Builds the results announcement.

(count: number) => string"No results" / "1 result" / "N results"
announceDelay

Quiet period (ms) before announcing resultsCount, to avoid chatter while typing.

number700
radius

Corner rounding.

"sm""md""lg""none""xs""xl""2xl""pill""pill"
ref

Ref to the <input> element.

Ref<HTMLInputElement>—
startIcon

Decorative icon before the text. Hidden from assistive technology.

ReactNode—
endIcon

Decorative icon after the text. Hidden from assistive technology.

ReactNode—
loading

Shows a decorative spinner at the end and sets aria-busy on the input. Announce the outcome of the async work elsewhere (e.g. a status message).

booleanfalse
fullWidth

Stretches the field to fill its container.

booleantrue
variant

Visual style.

"outline""filled""outline"
size

Control height, padding, and type size. Inherits from a surrounding Field when not set.

"sm""md""lg""md"
invalid

Marks the value as invalid: sets aria-invalid and a danger border. Pair it with a visible error message (a Field does this for you). Inherits from a surrounding Field.

booleanfalse
inputClassName

Class name for the <input> element. className goes to the wrapper.

string—
startAddon

Static content attached to the start edge, such as "https://" or a currency symbol. Text addons are announced as part of the input's description (aria-describedby).

ReactNode—
endAddon

Static content attached to the end edge, such as ".com" or a unit ("kg"). Text addons are announced as part of the input's description.

ReactNode—
startElement

Interactive content inside the start edge (for example an IconButton with size="sm" and variant="ghost"). Stays in the tab order; give it its own accessible name.

ReactNode—
endElement

Interactive content inside the end edge (for example a copy or show-password IconButton). Stays in the tab order; give it its own accessible name.

ReactNode—
htmlSize

The native size attribute (visible width in characters). Mostly useful with fullWidth={false}.

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.

SearchForm props
PropTypeDefault
children

The SearchInput plus any filters or a submit button.

ReactNode—
aria-label

Accessible name of the search landmark, e.g. "Site search".

string—
aria-labelledby

id of a visible heading or label naming the landmark.

string—
onSearch

Called 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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

37 passed · 0 failed · 28 not applicable · 10 to check by hand

Dark mode

Score 100

37 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

Keyboard
KeyAction
Ctrl+K/With shortcut: focuses the field from anywhere on the page.
EnterRuns the search.
EscapeClears the text; with blurOnEscape, a second press leaves the field.

Roles and states

Roles and states
ElementRoleStates and properties
<input type="search">searchboxaria-keyshortcuts when there's a shortcut
SearchFormsearchA <form> landmark
Result countstatusAnnounced politely

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)