Navbar with search
Documentation or catalog header with a prominent search form and a short list of utility links.
pnpm dlx shadcn@latest add @haze/navbar-search---
import { Search } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import Button from "../ui/button.astro";
import Input from "../ui/input.astro";
import LogoMark from "../ui/logo-mark.astro";
interface Link { label: string; href: string; current?: boolean }
interface Props {
id?: string;
brand?: string;
homeHref?: string;
searchHref?: string;
searchName?: string;
searchLabel?: string;
searchPlaceholder?: string;
searchValue?: string;
submitLabel?: string;
links?: Link[];
navLabel?: string;
class?: string;
}
const {
id = "haze-search-navbar",
brand = "Fieldwork",
homeHref = "/",
searchHref = "/browse/",
searchName = "q",
searchLabel = "Search the library",
searchPlaceholder = "Search components…",
searchValue,
submitLabel = "Search",
links = [{ label: "Docs", href: "/docs/" }, { label: "Blocks", href: "/browse?kind=block" }],
navLabel = "Quick links",
class: className,
} = Astro.props;
---
<header class={cn("border-b border-border bg-muted/40", className)}>
<div class="mx-auto grid max-w-6xl grid-cols-[minmax(0,1fr)_auto] items-center gap-x-2 gap-y-3 px-4 py-3 sm:gap-x-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,27rem)_minmax(0,1fr)] lg:px-6">
<a href={homeHref} aria-label={`${brand} home`} class="inline-flex min-h-9 w-fit max-w-full items-center rounded-md wrap-anywhere focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring">
<LogoMark name={brand} shape="square" class="min-w-0 text-foreground [&_svg]:shrink-0" />
</a>
<form role="search" aria-label={searchLabel} action={searchHref} method="get" class="col-span-2 row-start-2 flex min-w-0 items-center gap-2 lg:col-span-1 lg:col-start-2 lg:row-start-1">
<div class="relative min-w-0 flex-1">
<label for={`${id}-field`} class="sr-only">{searchLabel}</label>
<Search aria-hidden="true" class="pointer-events-none absolute inset-s-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
<Input id={`${id}-field`} type="search" name={searchName} placeholder={searchPlaceholder} value={searchValue} class="ps-9" />
</div>
<Button variant="secondary" type="submit" class="h-auto min-h-9 max-w-28 py-1.5 whitespace-normal wrap-anywhere">{submitLabel}</Button>
</form>
{links.length > 0 && (
<nav aria-label={navLabel} class="col-start-2 row-start-1 min-w-0 justify-self-end lg:col-start-3">
<ul role="list" class="flex max-w-36 flex-wrap justify-end gap-0.5 sm:max-w-none">
{links.map((link) => (
<li class="max-w-full"><a href={link.href} aria-current={link.current ? "page" : undefined}
class="inline-flex min-h-9 items-center rounded-md px-2 text-[0.8125rem]/5 font-medium wrap-anywhere text-muted-foreground transition-colors duration-150 hover:bg-foreground/8 hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring aria-[current=page]:bg-foreground/8 aria-[current=page]:text-foreground">{link.label}</a></li>
))}
</ul>
</nav>
)}
</div>
</header>When to use
- Searching is a primary way visitors find a component, article, or product
- Visitors should be able to search even when scripting is disabled
When not to use
- The site has no search destination. Use navbar-simple.
- Visitors need deep grouped navigation. Use navbar-mega-menu.
Installation
Add the Haze registry to components.json once, then install Navbar with search with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/navbar-searchnpx shadcn@latest add @haze/navbar-searchyarn dlx shadcn@latest add @haze/navbar-searchbunx --bun shadcn@latest add @haze/navbar-searchFirst 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
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-search-navbar" | Unique prefix for the search input ID. |
| brand | string | "Fieldwork" | Text shown beside the brand mark. |
| homeHref | string | "/" | Path to the site home. |
| searchHref | string | "/browse/" | Page that receives the search query via GET. |
| searchName | string | "q" | Query parameter name expected by the destination. |
| searchLabel | string | "Search the library" | Accessible name of the form and input. |
| searchPlaceholder | string | "Search components…" | Example or hint shown in the empty input. |
| searchValue | string | – | Populate the field with the current search term on a results page. |
| submitLabel | string | "Search" | Visible text on the submit button. |
| links | Link[] | Docs, Blocks | Short utility links. Set current on the link for this page. |
| navLabel | string | "Quick links" | Accessible name of the quick links. |
| class | string | – | Additional classes on the header. |
Keyboard interactions
- Tab
- Reach the search field, submit button, and utility links.
- Enter
- Submit the query from the field or button.
Accessibility
- The visually hidden input label persists when the placeholder disappears.
- Search stays visible on a second row on small screens.
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 block "Navbar with search" with `npx shadcn@latest add @haze/navbar-search`. 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 NavbarSearch from "@/components/haze/blocks/navbar-search.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/blocks/navbar-search.md
Customize with real content
Adapt the Haze navbar-search block for our product. Replace the demo values of these props with our real content: id, brand, homeHref, searchHref, searchName, searchLabel, searchPlaceholder, searchValue, submitLabel, links, navLabel, class. Keep the layout, the heading level rules and these accessibility details: The visually hidden input label persists when the placeholder disappears. Search stays visible on a second row on small screens. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using navbar-search, check it fits: use it when searching is a primary way visitors find a component, article, or product; visitors should be able to search even when scripting is disabled. Avoid it when the site has no search destination. use navbar-simple.; visitors need deep grouped navigation. use navbar-mega-menu.. Alternatives: @haze/navbar-simple, @haze/navbar-mega-menu, @haze/command-menu.
Dependencies
- npm: @lucide/astro
- @haze/button
- @haze/input
- @haze/logo-mark
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.