Sidebar
Grouped side navigation with native disclosures, active links, and slots for a workspace header and utility links.
pnpm dlx shadcn@latest add @haze/sidebar---
import { ChevronRight } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
type Icon = (props: Record<string, unknown>) => unknown;
interface SidebarLink { label: string; href: string; icon?: Icon; detail?: string; current?: boolean }
interface Group { label: string; icon?: Icon; links: SidebarLink[]; open?: boolean }
interface Props {
label?: string;
groups: Group[];
class?: string;
}
const { label = "Sidebar navigation", groups, class: className } = Astro.props;
---
<nav aria-label={label} class={cn("grid w-full max-w-72 min-w-0 content-start rounded-xl border border-border bg-card text-card-foreground", className)}>
{Astro.slots.has("header") && <div class="min-w-0 border-b border-border p-3 wrap-anywhere"><slot name="header" /></div>}
<div class="grid gap-1 p-2">
{groups.map((group) => (
<details open={group.open ?? group.links.some((link) => link.current)} class="group min-w-0 supports-[interpolate-size:allow-keywords]:[interpolate-size:allow-keywords] supports-[interpolate-size:allow-keywords]:details-content:h-0 supports-[interpolate-size:allow-keywords]:details-content:overflow-clip supports-[interpolate-size:allow-keywords]:details-content:transition-[height,content-visibility] supports-[interpolate-size:allow-keywords]:details-content:transition-discrete supports-[interpolate-size:allow-keywords]:details-content:duration-300 supports-[interpolate-size:allow-keywords]:details-content:ease-snappy supports-[interpolate-size:allow-keywords]:open:details-content:h-auto">
<summary class="flex min-h-10 cursor-pointer list-none items-center gap-2 rounded-lg px-2 py-1.5 text-[0.8125rem]/5 font-medium text-foreground transition-[background-color] duration-150 ease-snappy [details:not([open])>&]:hover:bg-accent focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
{group.icon && <span class="shrink-0 text-muted-foreground [&_svg]:size-4"><group.icon aria-hidden="true" /></span>}
<span class="min-w-0 flex-1 wrap-anywhere">{group.label}</span>
<ChevronRight aria-hidden="true" class="size-3.5 shrink-0 text-muted-foreground transition-[rotate,color] duration-200 ease-spring motion-reduce:transition-none group-open:text-foreground group-open:rotate-90 rtl:rotate-180 rtl:group-open:rotate-90" />
</summary>
<ul role="list" class="ms-3.5 mt-1 mb-1 grid gap-1 border-s border-border ps-2 transition-opacity duration-150 ease-snappy group-[&:not([open])]:opacity-0 motion-reduce:transition-none">
{group.links.map((link) => (
<li><a href={link.href} aria-current={link.current ? "page" : undefined}
class="flex min-h-8 items-center gap-2 rounded-md px-2 py-1.5 text-[0.8125rem]/5 text-muted-foreground transition-colors duration-150 ease-snappy hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring aria-[current=page]:bg-accent aria-[current=page]:font-medium aria-[current=page]:text-foreground forced-colors:aria-[current=page]:underline">
{link.icon && <span class="shrink-0 [&_svg]:size-3.5"><link.icon aria-hidden="true" /></span>}
<span class="min-w-0 flex-1 wrap-anywhere">{link.label}</span>
{link.detail && <span class="max-w-[50%] shrink-0 self-center rounded-sm bg-muted px-1.5 text-[0.6875rem]/4 font-medium text-muted-foreground wrap-anywhere tabular-nums">{link.detail}</span>}
</a></li>
))}
</ul>
</details>
))}
</div>
{Astro.slots.has("footer") && <div class="min-w-0 border-t border-border p-2"><slot name="footer" /></div>}
</nav>When to use
- A dashboard or documentation site needs persistent navigation with one level of grouping
- The sidebar needs a workspace switcher or footer utilities supplied by the application
When not to use
- The sidebar is hidden behind a mobile trigger. Compose it with drawer.
- The links point to headings on a single page. Use table-of-contents.
Installation
Add the Haze registry to components.json once, then install Sidebar with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/sidebarnpx shadcn@latest add @haze/sidebaryarn dlx shadcn@latest add @haze/sidebarbunx --bun shadcn@latest add @haze/sidebarFirst 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 |
|---|---|---|---|
| groups* | { label: string; icon?: AstroComponent; links: SidebarLink[]; open?: boolean }[] | – | Each group contains page links with label, href, optional icon and detail, and current-page state. A group with the current page starts open. |
| label | string | "Sidebar navigation" | Accessible name of the navigation landmark. |
| class | string | – | Additional classes for placement or sizing. |
Keyboard interactions
- EnterSpace
- Toggle the focused group.
- TabShiftTab
- Move among summaries, revealed page links, and slotted controls.
Accessibility
- Each group is a native disclosure. Groups can remain open independently.
- Mark the selected page with current. It has a text-weight change, a different fill, and aria-current.
- Use the header slot for a workspace name and the footer slot for links such as help.
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 "Sidebar" with `npx shadcn@latest add @haze/sidebar`. 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 Sidebar from "@/components/haze/ui/sidebar.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/sidebar.md
Customize with real content
Adapt the Haze sidebar ui for our product. Replace the demo values of these props with our real content: groups, label, class. Keep the layout, the heading level rules and these accessibility details: Each group is a native disclosure. Groups can remain open independently. Mark the selected page with current. It has a text-weight change, a different fill, and aria-current. Use the header slot for a workspace name and the footer slot for links such as help. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using sidebar, check it fits: use it when a dashboard or documentation site needs persistent navigation with one level of grouping; the sidebar needs a workspace switcher or footer utilities supplied by the application. Avoid it when the sidebar is hidden behind a mobile trigger. compose it with drawer.; the links point to headings on a single page. use table-of-contents.. Alternatives: @haze/navigation-menu, @haze/table-of-contents, @haze/bottom-navigation, @haze/drawer.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.