Skip to content

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

By name or description, across the 24 props below

SearchField 24 props

  • idtype string

    The input's id.

  • aria-controlstype string

    The id of what the search filters, e.g. a list of results.

  • valuetype string

    Controlled query.

  • defaultValuetype stringdefault ""

    Initial query when uncontrolled.

  • placeholdertype string

    Hint text shown in the empty input, e.g. "Search settings".

  • leadingIcontype ReactNode

    Leading icon, usually a search icon, or a back button.

  • trailingIcontype ReactNode

    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.

  • clearIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Replaces the clear button's icon (Material Symbols close).

  • densitytype 0 | -1 | -2 | -3default 0

    Web density, 0 to -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 nearest ThemeProvider or ThemeScope. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there, from a setting.

  • disabledtype boolean

    Whether the field is disabled: it takes no input and shows no clear button.

  • autoFocustype boolean

    Focus the input when the field mounts.

  • inputReftype Ref<HTMLInputElement>

    The input element.

  • inputPropstype SearchFieldInputProps

    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.

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element.

Events

  • onChangetype ((value: string) => void)

    Called with the query as it changes, by typing, Escape or the clear button.

  • onSubmittype ((value: string) => void)

    Called with the query when the user presses Enter (the keyboard's search action).

Text

  • aria-describedbytype string

    The ids of elements that describe the search, before any inputProps['aria-describedby'].

  • aria-detailstype string

    The id of an element with more details about the search.

  • labelstype Partial<SearchFieldLabels>

    Words the field shows or announces, in place of the English defaults. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    The search box's accessible name. Required unless aria-labelledby is set.

  • aria-labelledbytype string

    The id of the element that names the search box. Required unless aria-label is set.

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.

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

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-* or h-* 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 (an img, drawn at 30px).