Skip to content
Ginga UI
Ginga UI
日本語

Getting started

  • Overview
  • Quick start
  • Theme generation
  • Custom rendering
  • All components

Forms

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

Display

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

Typography

  • Heading
  • Paragraph

Navigation

  • Anchor

Layout

  • Box

Resources

  • Changelog
  • GitHub (opens in a new tab)

Logo: Twemoji (opens in a new tab) (CC-BY 4.0)

SearchField

A search input with a clear button. Esc clears the value and Enter submits it.

View in Storybook (opens in a new tab)

Installation

import { SearchField } from "@ginga-ui/core";

Basic usage

The label is read by screen readers but not shown. A clear button appears when there is a value.

search-field.tsx
import { SearchField } from "@ginga-ui/core";
import { Search } from "lucide-react";

export function BasicExample() {
  return (
    <SearchField
      label="Search"
      placeholder="Enter keywords"
      icon={<Search />}
    />
  );
}

Showing the label

Pass showLabel to show the label above the field. onSubmit is called when Enter is pressed.

Press Enter to search and Esc to clear
search-field.tsx
import { SearchField } from "@ginga-ui/core";
import { Search } from "lucide-react";

export function ShowLabelExample() {
  return (
    <SearchField
      label="Search"
      showLabel
      placeholder="Enter keywords"
      description="Press Enter to search and Esc to clear"
      onSubmit={(value) => console.log("Search:", value)}
    />
  );
}

Icons

Use icon for a leading icon and clearIcon for the clear button.

search-field.tsx
import { SearchField } from "@ginga-ui/core";
import { Search, X } from "lucide-react";

export function IconExample() {
  return (
    <SearchField
      label="Search components"
      placeholder="Search components"
      defaultValue="Ginga UI"
      icon={<Search />}
      clearIcon={<X />}
    />
  );
}

Disabled

Pass disabled to disable the field.

search-field.tsx
import { SearchField } from "@ginga-ui/core";
import { Search } from "lucide-react";

export function DisabledExample() {
  return (
    <SearchField
      label="Search"
      defaultValue="Ginga UI"
      disabled
      icon={<Search />}
    />
  );
}

Props

SearchField

NameTypeDefaultDescription
labelstring-Label of the field. It is read by screen readers and is visually hidden unless showLabel is set. Use aria-label instead when omitted.
showLabelbooleanfalseShows the label above the field.
placeholderstring-Placeholder text of the input.
descriptionReactNode-Help text shown below the field.
errorMessageReactNode | ((validation: ValidationResult) => ReactNode)-Error message shown when the value is invalid.
disabledbooleanfalseDisables the field.
requiredbooleanfalseRequires a value.
readOnlybooleanfalseMakes the field read-only.
invalidbooleanfalseShows the field as invalid.
iconReactNode-Icon shown before the input.
clearIconReactNode-Icon of the clear button. A cross is drawn when omitted.

Also accepts the props of React Aria's SearchField (opens in a new tab).