Search field

Free

A search field with its ⌘K hint at rest, a clear button once there is text, Esc to clear, and Enter that never fires mid-composition.

npx shadcn@latest add https://pixilui.com/r/search-field.json

Preview

Esc clears, and Enter waits for composition to finish.
Size

When to use

Use it when

  • Searching runs, agents and people in a panel or a header.

Use something else when

  • A command palette: use the command menu.
  • Filtering by known groups: use Chip group.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/search-field.json

Adds search-field.tsx with field.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { SearchField } from "@/components/pixilui/search-field";

<SearchField
  aria-label={aria-label}
  clearIcon={clearIcon}
  onClear={onClear}
  onSubmit={onSubmit}
/>

Fills its container's width; the label row and the message wrap.

API reference

PropTypeDefault
aria-labelRequiredstring–The field's name for screen readers ("Search runs"). Search usually has no visible label.
clearIconRequiredReactNode–The clear button's icon (a cross).
iconReactNode–The search icon before the text (the animated search icon).
shortcutReactNode–The shortcut that focuses it, shown at rest without a value: "⌘K". Wiring the key itself is the page's job.
clearLabelstring"Clear"The clear button's name.
onClear() => void–Runs after the clear button or Esc empties the field.
onSubmit(query: string) => void–Runs on Enter with the trimmed text.

Also takes every native <input> attribute except size, prefix, onSubmit, and a ref.

Keyboard

EscClears the text when there is some.
EnterRuns onSubmit with the text, never in the middle of composing.

Accessibility

  • Named by its aria-label; the clear button is a labelled button.

Motion

  • The shortcut hint and the clear button swap as text arrives and leaves; nothing animates on keys.
InputA field that checks what you typed and says what's wrong in words.
Chip groupPress a filter and only the changed digits of the total roll.
AI fieldA still gradient rim marks the field that asks the agent.

PixilUI Pro opens soon. The first 20 licenses are $99.