Skip to Content
NarakUI

Search Field

A search input built on ui-sdk with an automatic Clear button that empties the field and restores focus.

Basic usage

SearchField composes @ui-sdk/react/input (InputGroup, Input, and InputClear) with @ui-sdk/react/field. The Clear button renders only while the input contains text; activating it empties the value, reports "clear-press", and returns focus to the input.

Showing matches for "Geist Rounded" (initial)

Installation

pnpm dlx shadcn@latest add @narakui/search-field

Add "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/search-field.json.

Usage

import { SearchField } from '@/components/ui/search-field';

<SearchField
  label="Search documentation"
  placeholder="Search components..."
  defaultValue="Button"
/>

Or compose the parts directly:

import {
  SearchFieldClear,
  SearchFieldGroup,
  SearchFieldInput,
} from '@/components/ui/search-field';

<SearchFieldGroup>
  <SearchFieldInput aria-label="Search" placeholder="Search..." />
  <SearchFieldClear aria-label="Clear search" />
</SearchFieldGroup>

Properties

PropTypeDefaultDescription
labelReactNode—Visible label wired to the input via FieldLabel
endLabelReactNode—Content rendered at the end of the label row
placeholderstring—Placeholder text when the search field is empty
valuestring—Controlled input value
defaultValuestring—Initial value for uncontrolled usage and form reset
onValueChange(value: string, details: ChangeDetails<SearchFieldValueChangeReason>) => void—Called when the value changes from typing ("input-change"), pressing Clear ("clear-press"), form reset ("reset"), or a controller ("imperative")
controllerSearchFieldController—Controller created with createSearchFieldController()
size'mini' | 'micro' | 'small' | 'regular' | 'large''regular'Height and typography scale of the search field
variant'control' | 'chromeless''control'Surface treatment (control card shadow or chromeless)
iconStartReactNode | boolean<Search />Leading icon inside the group; pass false to omit
clearLabelstring'Clear search'Accessible label applied to the InputClear button
hintReactNode—Helper description linked via FieldDescription
errorbooleanfalseMarks the field invalid and applies error border styling
errorMessageReactNode—Error text shown via FieldError while error is true
disabledbooleanfalseDisables the input and hides the Clear button
readOnlybooleanfalseMakes the input read-only and hides the Clear button
requiredbooleanfalseMarks the search input required for form submission