Skip to content
Haze UI

Search field

A labeled native search input with a leading icon and a clear button that restores focus to the field.

pnpm dlx shadcn@latest add @haze/search-field
Open preview in a new tab
Livesmall script

When to use

  • A catalog or list needs a clearable query field.
  • A native GET form should submit text to a search results page.

When not to use

  • The user must choose a valid option from a list of suggestions.

Installation

Add the Haze registry to components.json once, then install Search field with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/search-field
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique ID for the input and its label association.
namestringidSubmitted query parameter name.
labelstringSearchAccessible name of the field.
hideLabelbooleanfalseKeeps the label available to assistive technology while hiding it visually.
placeholderstring–Short hint for the empty query.
valuestring–Initial query text.
clearLabelstringClear searchAccessible name of the clear button.
submitLabelstring–When set, renders a submit button in the same row as the field.
classstring–Classes on the field wrapper.

Keyboard interactions

Enter
Submit the query in a search form.
EnterSpace
Activate the focused clear button.

Accessibility

  • Clearing the field sends input and change events and returns focus to the query.
  • The field works as a native search control when scripts are unavailable.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Search field" with `npx shadcn@latest add @haze/search-field`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import SearchField from "@/components/haze/ui/search-field.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/search-field.md

  • Customize with real content

    Adapt the Haze search-field ui for our product. Replace the demo values of these props with our real content: id, name, label, hideLabel, placeholder, value, clearLabel, submitLabel, class. Keep the layout, the heading level rules and these accessibility details: Clearing the field sends input and change events and returns focus to the query. The field works as a native search control when scripts are unavailable. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using search-field, check it fits: use it when a catalog or list needs a clearable query field.; a native get form should submit text to a search results page.. Avoid it when the user must choose a valid option from a list of suggestions.. Alternatives: @haze/input-group, @haze/command-menu, @haze/combobox.

Dependencies

  • npm: @lucide/astro
  • @haze/button
  • @haze/input
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog