# Navbar with search

> Documentation or catalog header with a prominent search form and a short list of utility links.

- Kind: block · Category: Navbar · Interactivity: native
- Install: `npx shadcn@latest add @haze/navbar-search`
- File: `src/components/haze/blocks/navbar-search.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/button, @haze/input, @haze/logo-mark, @haze/utils
- Docs page: https://hazeui.com/blocks/navbar-search

## Use 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 when
- The site has no search destination. Use navbar-simple.
- Visitors need deep grouped navigation. Use navbar-mega-menu.

## Alternatives
- [navbar-simple](https://hazeui.com/blocks/navbar-simple.md)
- [navbar-mega-menu](https://hazeui.com/blocks/navbar-mega-menu.md)
- [command-menu](https://hazeui.com/ui/command-menu.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-search-navbar" | no | Unique prefix for the search input ID. |
| brand | `string` | "Fieldwork" | no | Text shown beside the brand mark. |
| homeHref | `string` | "/" | no | Path to the site home. |
| searchHref | `string` | "/browse/" | no | Page that receives the search query via GET. |
| searchName | `string` | "q" | no | Query parameter name expected by the destination. |
| searchLabel | `string` | "Search the library" | no | Accessible name of the form and input. |
| searchPlaceholder | `string` | "Search components…" | no | Example or hint shown in the empty input. |
| searchValue | `string` |  | no | Populate the field with the current search term on a results page. |
| submitLabel | `string` | "Search" | no | Visible text on the submit button. |
| links | `Link[]` | Docs, Blocks | no | Short utility links. Set current on the link for this page. |
| navLabel | `string` | "Quick links" | no | Accessible name of the quick links. |
| class | `string` |  | no | Additional classes on the header. |

## Accessibility
- The visually hidden input label persists when the placeholder disappears.
- Search stays visible on a second row on small screens.
- Key Tab: Reach the search field, submit button, and utility links.
- Key Enter: Submit the query from the field or button.

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Create a docs header with a central search field and two shortcut links
- Add native GET search to a catalog header with a full row for the field on phones

## Source

```astro
---
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>
```
