Search field
The search bar's 56px pill as a search box that filters a page, a list or a table in place, with a clear button. It never opens a search view.
import { SearchField } from '@windmorph/react';Props
SearchField 24 props
The input's id.
The id of what the search filters, e.g. a list of results.
Controlled query.
Initial query when uncontrolled.
Hint text shown in the empty input, e.g. "Search settings".
Leading icon, usually a search icon, or a back button.
Trailing content after the clear button: an icon button (e.g. voice search), or an avatar (an
img, drawn at 30px), as in the search bar.Replaces the clear button's icon (Material Symbols
close).Web density,
0to-3: each step takes 4px off the pill (56px at 0, 44px at -3), as on the other fields; icon buttons in it keep their 48px touch targets. Left out, the field takes the density of the nearestThemeProviderorThemeScope. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there, from a setting.Whether the field is disabled: it takes no input and shows no clear button.
Focus the input when the field mounts.
The input element.
Attributes for the input. They replace the field's defaults (
enterKeyHint="search",autoComplete="off",spellCheck={false}); event handlers run before the field's own, and its role, name, value and type always win.Ref to the root
<div>element.
Events
Called with the query as it changes, by typing, Escape or the clear button.
Called with the query when the user presses Enter (the keyboard's search action).
Text
The ids of elements that describe the search, before any
inputProps['aria-describedby'].The id of an element with more details about the search.
Words the field shows or announces, in place of the English defaults. A
LabelsProvidersets them for the whole app.The search box's accessible name. Required unless
aria-labelledbyis set.The id of the element that names the search box. Required unless
aria-labelis set.
Classes for the root element, merged with
classNames.root; consumer classes win.Inline styles for the root element.
Classes for each part, by slot.
The outer container, merged with
className.The pill around the icons and the input.
The text input.
The leading icon slot.
The trailing slot, holding the clear button and
trailingIcon.The clear button.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Spec status
Built to the M3 Expressive search field spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Search bar | Built | Variant · Filter |
| Leading and trailing icons | Built | Configuration · Trailing |
| Filtering content in place | Built | Use case · Filter, Pane |
| Clear button | Extension | A standard icon button in the trailing slot while there is text; it clears and keeps focus in the input. Escape clears too. |
| Disabled | Extension | M3's disabled colours, as other fields: the content on-surface at 38% and the container at 12%. |
| Full width | Extension | It fills its container, where the search bar is 360px wide by default, so it fits a page, a list pane or a table toolbar. |
| Search view | Not built | It never opens one: use the Search bar for suggestions or results. |
Search bar
BuiltVariant · Filter
Leading and trailing icons
BuiltConfiguration · Trailing
Clear button
ExtensionA standard icon button in the trailing slot while there is text; it clears and keeps focus in the input. Escape clears too.
Disabled
ExtensionM3's disabled colours, as other fields: the content
on-surfaceat 38% and the container at 12%.Full width
ExtensionIt fills its container, where the search bar is 360px wide by default, so it fits a page, a list pane or a table toolbar.
Search view
Not builtIt never opens one: use the Search bar for suggestions or results.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
SearchField: 30.7 kB
Tokens and shape
- It reads the search bar's tokens (
md-comp-search-bar, listed on the Search page), so a theme or a scoped override restyles the search field and the search bar together. - It's 56px tall, as M3's search bar, and fills its container; a consumer
w-*orh-*class wins.density(or the theme's) takes 4px off a step, down to 44px at -3, for a dense table or list; its icon buttons keep 48px touch targets. - The trailing slot holds the clear button and
trailingIcon: one icon button, or an avatar (animg, drawn at 30px).