Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Search Field

A text field for searching, with a search icon and a button that clears it.

Built on the headless Search Field.See its API in Docs

Rendered by React 19.3.1

search-field.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/search-field.json

It also adds utils, button. The app needs its setup first: Installation.

Usage

Put a SearchFieldIcon, a SearchFieldInput and a SearchFieldClear inside a SearchField. The Icon draws a magnifying glass unless it has content of its own, and the Clear draws an X. Name the field with a Field label or aria-label; the Clear is named "Clear search". The Clear is shown while the field has something to clear and is not read-only, it is not a tab stop, and pressing it empties the field and returns focus to the Input. Enter calls the Root's search callback (onSearch, the search event in Vue, a function input in Angular) and Escape clears a filled field. The value, the IME composition, the form reset and the keys inside a Dialog or Popover come from the headless Search Field.

import {
  SearchField,
  SearchFieldClear,
  SearchFieldIcon,
  SearchFieldInput,
} from '@/components/ui/search-field'

Examples

Default

A labelled search field with the icon and the Clear button.

Its preview and code are at the top of the page.

The Input is the Input's with ps-9 and pe-9 so the text never runs under the icon or the Clear; both sit at the inline start and end of the Root and follow the writing direction. The Clear is the Button's ghost variant at the 24px icon-xs size, so it meets the target size of WCAG 2.5.8, and it is hidden until data-visible. The Input is type="text" with role="searchbox" by default, so the browser draws no clear control of its own and the item carries no WebKit reset. This item takes Base UI's component ID as its slug and one name per Base UI part; shadcn has no search field.

API reference

The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Search Field's API reference.