Bottom navigation
Mobile app navigation with labeled icons, a current-page indicator, and padding for a bottom safe area.
pnpm dlx shadcn@latest add @haze/bottom-navigation---
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>When to use
- A mobile app needs quick access to three to five primary destinations
- The current destination should stay visible in a compact, touch-friendly bar
When not to use
- There are more than five primary destinations. Use sidebar or navigation-menu.
- The controls switch panels under one URL. Use tabs.
Installation
Add the Haze registry to components.json once, then install Bottom navigation with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/bottom-navigationnpx shadcn@latest add @haze/bottom-navigationyarn dlx shadcn@latest add @haze/bottom-navigationbunx --bun shadcn@latest add @haze/bottom-navigationFirst 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 |
|---|---|---|---|
| items* | { label: string; href: string; icon: AstroComponent; current?: boolean }[] | – | Page destinations with short, visible labels. Mark the current page with current. |
| label | string | "App navigation" | Accessible name of the navigation landmark. |
| class | string | – | Additional classes for positioning. Reserve room for content when using fixed positioning. |
Keyboard interactions
- Tab
- Reach each destination in reading order.
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.
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 "Bottom navigation" with `npx shadcn@latest add @haze/bottom-navigation`. 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 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: http://localhost:4329/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.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.