Menu

Search field

Search bar with shortcut hint. 3 sizes × 3 states.

Installation

$ npx uix-ui@latest add search-field

This copies the file into components/ui/search-field.tsx in your project. npx shadcn@latest add @uix/search-field works too.

Usage

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

<div style={{ width: 320, maxWidth: "100%" }}>
  <SearchField placeholder="Search teas" aria-label="Search teas" value={q} onChange={e => setQ(e.target.value)} onClear={() => setQ("")} />
</div>

Props

PropTypeDefaultDescription
sizesm | md | lg"md"
onClear() => void–Called by the clear button, which shows while the field has a value.
shortcutReact.ReactNode–Shortcut hint (for example a Kbd) shown while the field is empty.
leadingAvatarReact.ReactNode–Avatar at the start (for example <Avatar size="xs" initials="AB" />).
leadingIconReact.ReactNode–Icon at the start.
leadingContentReact.ReactNode–Selector or text at the start, for example "Email ▾".
leadingDividerboolean–Hairline after the leading parts.
prefixReact.ReactNode–Fixed text before the value, for example "https://".
tagsReact.ReactNode[]–Tag chips before the value.
suffixReact.ReactNode–Fixed text after the value, for example ".com".
trailingDividerboolean–Hairline before the trailing parts.
trailingContentReact.ReactNode–Action at the end, for example a "Copy" button.
helpIconboolean | string–Help icon; a string becomes its accessible name and tooltip.
trailingIconReact.ReactNode–Icon at the end.

Everything else is passed to the root element, so className, aria-* and event handlers work as usual.

Dependencies

Installed for you by the CLI.

  • class-variance-authority
  • clsx
  • tailwind-merge
  • lib/utils.ts
  • components/ui/icons.tsx
esc

↑↓ to navigate · ↵ to select · esc to close