# Sidebar

> Grouped side navigation with native disclosures, active links, and slots for a workspace header and utility links.

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

## Use 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 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
- [navigation-menu](https://hazeui.com/ui/navigation-menu.md)
- [table-of-contents](https://hazeui.com/ui/table-of-contents.md)
- [bottom-navigation](https://hazeui.com/ui/bottom-navigation.md)
- [drawer](https://hazeui.com/ui/drawer.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| groups | `{ label: string; icon?: AstroComponent; links: SidebarLink[]; open?: boolean }[]` |  | yes | 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" | no | Accessible name of the navigation landmark. |
| class | `string` |  | no | Additional classes for placement or sizing. |

## 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.
- Key Enter / Space: Toggle the focused group.
- Key Tab / Shift+Tab: Move among summaries, revealed page links, and slotted controls.

## Agent prompts

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

## Example requests that should lead here
- Give a dashboard a sidebar with Project and Settings groups and an active Overview link
- Put a workspace switcher above grouped documentation links and a support link below

## Source

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