# Bottom navigation

> Mobile app navigation with labeled icons, a current-page indicator, and padding for a bottom safe area.

- Kind: ui · Category: Navigation · Interactivity: script
- Install: `npx shadcn@latest add @haze/bottom-navigation`
- File: `src/components/haze/ui/bottom-navigation.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/bottom-navigation

## Use when
- A mobile app needs quick access to three to five primary destinations
- The current destination should stay visible in a compact, touch-friendly bar

## Avoid when
- There are more than five primary destinations. Use sidebar or navigation-menu.
- The controls switch panels under one URL. Use tabs.

## Alternatives
- [sidebar](https://hazeui.com/ui/sidebar.md)
- [navigation-menu](https://hazeui.com/ui/navigation-menu.md)
- [tabs](https://hazeui.com/ui/tabs.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| items | `{ label: string; href: string; icon: AstroComponent; current?: boolean }[]` |  | yes | Page destinations with short, visible labels. Mark the current page with current. |
| label | `string` | "App navigation" | no | Accessible name of the navigation landmark. |
| class | `string` |  | no | Additional classes for positioning. Reserve room for content when using fixed positioning. |

## Accessibility
- Links have visible labels and minimum 48 px height. Icons are decorative.
- The selected destination uses aria-current, a stronger label weight and one sliding key behind the icon and label.
- Layout wraps when the destinations exceed the available width.
- Key Tab: Reach each destination in reading order.

## Agent prompts

### Install and use

Install the Haze UI component "Bottom navigation" with `npx shadcn@latest add @haze/bottom-navigation`. 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 BottomNavigation from "@/components/haze/ui/bottom-navigation.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/ui/bottom-navigation.md

### Customize with real content

Adapt the Haze bottom-navigation ui for our product. Replace the demo values of these props with our real content: items, label, class. Keep the layout, the heading level rules and these accessibility details: Links have visible labels and minimum 48 px height. Icons are decorative. The selected destination uses aria-current, a stronger label weight and one sliding key behind the icon and label. Layout wraps when the destinations exceed the available width. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using bottom-navigation, check it fits: use it when a mobile app needs quick access to three to five primary destinations; the current destination should stay visible in a compact, touch-friendly bar. Avoid it when there are more than five primary destinations. use sidebar or navigation-menu.; the controls switch panels under one url. use tabs.. Alternatives: @haze/sidebar, @haze/navigation-menu, @haze/tabs.

## Example requests that should lead here
- Create a mobile navigation bar with Home, Search, Saved, and Profile destinations
- Add safe-area padding to a bottom app bar and highlight the current destination

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";

interface Destination {
  label: string;
  href: string;
  icon: (props: Record<string, unknown>) => unknown;
  current?: boolean;
}
interface Props {
  items: Destination[];
  label?: string;
  class?: string;
}

const { items, label = "App navigation", class: className } = Astro.props;
---

<nav data-haze-bottom-nav aria-label={label} class={cn("w-full min-w-0 rounded-xl border border-border bg-card px-1.5 pt-1.5 pb-[max(0.375rem,env(safe-area-inset-bottom))] text-card-foreground", className)}>
  <ul role="list" class="relative isolate grid grid-cols-[repeat(auto-fit,minmax(min(100%,2.75rem),1fr))] gap-0.5">
    <li aria-hidden="true" data-bn-indicator class="pointer-events-none absolute top-0 left-0 -z-10 hidden h-(--bn-h) w-(--bn-w) translate-x-(--bn-x) rounded-lg bg-accent [[data-enhanced]_&]:block [[data-ready]_&]:transition-[translate,width] [[data-ready]_&]:duration-200 [[data-ready]_&]:ease-snappy motion-reduce:[[data-ready]_&]:transition-none"></li>
    {items.map((item) => (
      <li class="min-w-0">
        <a href={item.href} data-bn-item aria-current={item.current ? "page" : undefined}
          class="flex h-full min-h-12 flex-col items-center justify-center gap-0.5 rounded-lg px-1 py-1 text-center text-muted-foreground transition-[background-color,color,scale] duration-150 ease-snappy hover:text-foreground focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75 aria-[current=page]:bg-accent aria-[current=page]:font-medium aria-[current=page]:text-foreground [[data-enhanced]_&]:aria-[current=page]:bg-transparent forced-colors:aria-[current=page]:underline [&_svg]:size-[1.0625rem]">
          <item.icon aria-hidden="true" />
          <span class="max-w-full text-[0.6875rem]/4 wrap-anywhere">{item.label}</span>
        </a>
      </li>
    ))}
  </ul>
</nav>

<script>
  function enhance(root: HTMLElement) {
    if (root.hasAttribute("data-enhanced")) return;
    root.setAttribute("data-enhanced", "");
    const indicator = root.querySelector<HTMLElement>("[data-bn-indicator]");
    const links = Array.from(root.querySelectorAll<HTMLElement>("[data-bn-item]"));
    if (!indicator || links.length === 0) return;
    const place = (slide: boolean, target?: HTMLElement) => {
      const current = target ?? links.find((link) => link.getAttribute("aria-current") === "page");
      root.toggleAttribute("data-ready", slide);
      indicator.style.visibility = current ? "" : "hidden";
      if (!current) return;
      indicator.style.setProperty("--bn-x", `${current.offsetLeft}px`);
      indicator.style.setProperty("--bn-w", `${current.offsetWidth}px`);
      indicator.style.setProperty("--bn-h", `${current.offsetHeight}px`);
    };
    links.forEach((link) => link.addEventListener("click", (event) => {
      if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
      if (link.getAttribute("href")?.startsWith("#")) {
        links.forEach((other) => other === link ? other.setAttribute("aria-current", "page") : other.removeAttribute("aria-current"));
      }
      place(true, link);
    }));
    place(false);
    if ("ResizeObserver" in window) new ResizeObserver(() => place(false)).observe(root);
  }

  const init = () => document.querySelectorAll<HTMLElement>("[data-haze-bottom-nav]").forEach(enhance);
  init();
  if (!document.documentElement.hasAttribute("data-haze-bottom-nav-listener")) {
    document.documentElement.setAttribute("data-haze-bottom-nav-listener", "");
    document.addEventListener("astro:page-load", init);
  }
</script>
```
