Skip to content

SearchInput

Search-shaped input built on Input — leading search icon, clear button, debounced onSearch, and Enter-to-submit.

  • stable
  • since v0.1.0
  • 4.85 kB
  • forms
  • input

Renders type="search"; Escape clears the field; clear button has an accessible label.

Preview
Open
tsx

Three sizes are available: sm, md (default), and lg.

Preview
Open
tsx

onSearch fires debounceMs (default 200) after the user stops typing — useful for kicking off network calls without thrashing the server.

Preview
Open
tsx

onSubmit fires when the user presses Enter.

Preview
Open
tsx
Preview
Open
tsx
PropTypeDefaultDescription
variant
"outline"|"filled"|"ghost"|"flat"
"outline"
Visual treatment forwarded to the underlying `<Input>`.
placeholder
string
"Search…"
Placeholder text.
onSearch
((query: string) => void)
—
Debounced callback — fires `debounceMs` after the user stops typing.
debounceMs
number
200
Debounce delay in milliseconds for `onSearch`.
onSubmit
((query: string) => void)
—
Submit handler — fires on Enter.
className
string
—
style
CSSProperties
—
size
"sm"|"md"|"lg"
"md"
Control size — affects height, padding, and font size.
value
string
—
Controlled value. Pair with `onChange`.
defaultValue
string
—
Uncontrolled initial value.
onChange
((value: string) => void)
—
Called with the next value whenever the user changes the field.
disabled
boolean
—
Disables interaction and dims the field.
name
string
—
Submitted form field name.
readOnly
boolean
—
Renders the field as read-only — value is visible and selectable but not editable.
required
boolean
—
Marks the field as required for form submission.
autoFocus
boolean
—
Focuses the control on mount.
id
string
—
Element id — auto-generated via `useId` when omitted.
invalid
boolean
—
Renders the invalid state (red border, error styling) and sets `aria-invalid`.
  • Renders type="search" — assistive tech announces the field as a searchbox.
  • The clear button (rendered automatically when the field has a value) carries an accessible label and is keyboard reachable.
  • Pressing Escape clears the value and keeps focus on the input.
  • Provide an aria-label when there is no visible caption.
  • Tune debounceMs for your latency budget — 150–300 ms is a good default range.
  • Use onSubmit to trigger an explicit search on Enter (e.g. navigation), while onSearch powers live filtering.
  • Place above a list and pipe the debounced query through your data fetching to filter results in place.