Search Field
A search input with a leading icon and a clear button; Escape clears and Enter submits.
Preview
Installation
pnpm add @syntara/react @syntara/tokensimport { SearchField } from '@syntara/react';Usage
import { SearchField } from '@syntara/react';
export function Search() {
return <SearchField aria-label="Search transactions" placeholder="Search transactions" onSubmit={(q) => search(q)} />;
}Examples
With label and description
In a toolbar
Same height as buttons at every density.
Accessibility
| Keys | Action |
|---|---|
| Enter | Calls onSubmit. |
| Escape | Clears the field (focus stays in the input). |
| Tab | Moves focus to the input; the clear button is not a tab stop. |
- The input has role searchbox.
- The clear button is hidden while the field is empty but keeps its space, so text never shifts.
- The search icon is decorative (aria-hidden).
Guidelines
Do
- Say what can be searched in the placeholder or label.
- Use aria-label only when a visible label would be redundant, e.g. a search above a table.
Don’t
- Don't hide results behind Enter when filtering a short list; filter on change.
- Don't put other buttons inside the field; place them beside it.
API reference
SearchField
labelReactNodeVisible label. Optional; without it, aria-label or aria-labelledby is required (enforced by the type).
aria-labelstringAccessible name when there is no visible label.
descriptionReactNodeHelp text, linked with aria-describedby.
errorMessagestring | ((validation: ValidationResult) => string)Shown with an icon when invalid.
placeholderstringHint text, e.g. what can be searched.
value / defaultValuestringControlled / uncontrolled value.
onChange(value: string) => voidCalled on every edit.
onSubmit(value: string) => voidCalled on Enter.
onClear() => voidCalled when cleared with Escape or the clear button.
clearLabelstringAccessible name of the clear button. Defaults to React Aria's localized "Clear search".
isDisabledbooleanDisables the field.
Default
falseinputRefRef<HTMLInputElement>Ref to the underlying input.
sizesmmddefaultlg
Height of the box: md is the density's control height, sm one 8px step shorter, lg two steps taller. Height, corner radius and inline inset match a Button of the same size, so a field and a button in one row line up.
Tokens
The semantic tokens this component reads, grouped by what they control. Swatches show this site’s theme; change a tenant’s brand and the component follows with no code change.
- Colour9
focus.ringtext.defaulttext.disabledtext.subtleborder.defaultborder.strongsurface.defaultsurface.sunkensurface.canvas- Type2
font.size.smfont.tracking.sm- Space and size6
control-heightspace.1space.2space.4space.6control-padding-inline- Shape1
radius.field- Motion4
motion.duration.fastmotion.duration.springmotion.easingmotion.spring