# Side Nav

Collapsible product navigation that integrates with AppShell compact mode.

`SideNav` is a compound product-navigation layout with collapsible sections, active-page state, and a compact rail. Its surface uses `--sidebar` (`#eceff1` in light mode and `#0f0f0f` in dark mode), falling back to `--background-default`. Collapsed item labels appear in tooltips by default. Inside AppShell, its toggle also drives the mobile and tablet-portrait sheet.

```tsx
import { ArrowLeftIcon, ArrowRightIcon, FolderIcon, GearIcon, HouseIcon, LifebuoyIcon, PulseIcon, UsersIcon } from "@phosphor-icons/react";
import { SideNav, Text } from "@zentara-co/zenos-ui";

const shellNavigation = [
  { label: "Overview", icon: HouseIcon },
  { label: "Projects", icon: FolderIcon },
  { label: "Activity", icon: PulseIcon },
];

function ProductSideNav({ defaultCollapsed = false }: { defaultCollapsed?: boolean }) {
  return (
    <SideNav aria-label="Workspace navigation" defaultCollapsed={defaultCollapsed}>
      <SideNav.Header
        collapsedContent={
          <SideNav.Toggle>
            <ArrowRightIcon aria-hidden="true" className="rtl:rotate-180" />
          </SideNav.Toggle>
        }
      >
        <Text weight="bold">ZENOS</Text>
        <SideNav.Toggle>
          {({ collapsed }) =>
            collapsed ? (
              <ArrowRightIcon aria-hidden="true" className="rtl:rotate-180" />
            ) : (
              <ArrowLeftIcon aria-hidden="true" className="rtl:rotate-180" />
            )
          }
        </SideNav.Toggle>
      </SideNav.Header>
      <SideNav.Content>
        <SideNav.Section label="Workspace">
          {shellNavigation.map((item, index) => (
            <SideNav.Item
              key={item.label}
              as="a"
              href={`#${item.label.toLowerCase()}`}
              active={index === 0}
              icon={<item.icon aria-hidden="true" />}
            >
              {item.label}
            </SideNav.Item>
          ))}
        </SideNav.Section>
        <SideNav.Section label="Manage">
          <SideNav.Item as="a" href="#members" icon={<UsersIcon aria-hidden="true" />}>
            Members
          </SideNav.Item>
          <SideNav.Item as="a" href="#settings" icon={<GearIcon aria-hidden="true" />}>
            Settings
          </SideNav.Item>
        </SideNav.Section>
      </SideNav.Content>
      <SideNav.Footer>
        <SideNav.Item as="a" href="#help" icon={<LifebuoyIcon aria-hidden="true" />}>
          Help and support
        </SideNav.Item>
      </SideNav.Footer>
    </SideNav>
  );
}

function SideNavExample() {
  return (
    <div className="h-[32rem]">
      <ProductSideNav />
    </div>
  );
}
```

## Import

```tsx
import { SideNav } from "@zentara-co/zenos-ui";
```

## Anatomy

```text
SideNav
├── SideNav.Header
│   └── SideNav.Toggle
├── SideNav.Content
│   └── SideNav.Section
│       └── SideNav.Item
└── SideNav.Footer
```

## Polymorphism

SideNav and its structural parts use the shared layout `as` API. The selected element's native props and ref type are preserved.

```tsx
<SideNav as="nav" aria-label="Workspace">
  <SideNav.Header as="header">Zenos</SideNav.Header>
  <SideNav.Content as="ul">
    <SideNav.Section as="li" label="Workspace">
      <SideNav.Item as="a" href="/overview">
        Overview
      </SideNav.Item>
    </SideNav.Section>
  </SideNav.Content>
  <SideNav.Footer as="footer">Help</SideNav.Footer>
</SideNav>
```

## Collapsed rail

Supply `collapsedContent` to Header so the rail retains a useful brand or expansion control. Labels remain available to assistive technology when visually collapsed, while item icons stay visible.

Item tooltips are enabled by default and appear only while the rail is collapsed. Disable them for the entire navigation when another nearby surface already identifies each item:

```tsx
<SideNav tooltip={false} aria-label="Workspace">
  {/* ... */}
</SideNav>
```

```tsx
import { ArrowLeftIcon, ArrowRightIcon, FolderIcon, GearIcon, HouseIcon, LifebuoyIcon, PulseIcon, UsersIcon } from "@phosphor-icons/react";
import { SideNav, Text } from "@zentara-co/zenos-ui";

const shellNavigation = [
  { label: "Overview", icon: HouseIcon },
  { label: "Projects", icon: FolderIcon },
  { label: "Activity", icon: PulseIcon },
];

function ProductSideNav({ defaultCollapsed = false }: { defaultCollapsed?: boolean }) {
  return (
    <SideNav aria-label="Workspace navigation" defaultCollapsed={defaultCollapsed}>
      <SideNav.Header
        collapsedContent={
          <SideNav.Toggle>
            <ArrowRightIcon aria-hidden="true" className="rtl:rotate-180" />
          </SideNav.Toggle>
        }
      >
        <Text weight="bold">ZENOS</Text>
        <SideNav.Toggle>
          {({ collapsed }) =>
            collapsed ? (
              <ArrowRightIcon aria-hidden="true" className="rtl:rotate-180" />
            ) : (
              <ArrowLeftIcon aria-hidden="true" className="rtl:rotate-180" />
            )
          }
        </SideNav.Toggle>
      </SideNav.Header>
      <SideNav.Content>
        <SideNav.Section label="Workspace">
          {shellNavigation.map((item, index) => (
            <SideNav.Item
              key={item.label}
              as="a"
              href={`#${item.label.toLowerCase()}`}
              active={index === 0}
              icon={<item.icon aria-hidden="true" />}
            >
              {item.label}
            </SideNav.Item>
          ))}
        </SideNav.Section>
        <SideNav.Section label="Manage">
          <SideNav.Item as="a" href="#members" icon={<UsersIcon aria-hidden="true" />}>
            Members
          </SideNav.Item>
          <SideNav.Item as="a" href="#settings" icon={<GearIcon aria-hidden="true" />}>
            Settings
          </SideNav.Item>
        </SideNav.Section>
      </SideNav.Content>
      <SideNav.Footer>
        <SideNav.Item as="a" href="#help" icon={<LifebuoyIcon aria-hidden="true" />}>
          Help and support
        </SideNav.Item>
      </SideNav.Footer>
    </SideNav>
  );
}

function SideNavCollapsedExample() {
  return (
    <div className="h-[28rem]">
      <ProductSideNav defaultCollapsed />
    </div>
  );
}
```

## Controlled state

Outside AppShell, use `collapsed` and `onCollapsedChange` to coordinate the rail with application state. `defaultCollapsed` provides the uncontrolled form.

```tsx
import { ArrowLeftIcon, ArrowRightIcon, FolderIcon, HouseIcon } from "@phosphor-icons/react";
import { Button, SideNav, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function SideNavControlledExample() {
  const [collapsed, setCollapsed] = useState(false);

  return (
    <Stack direction="row" gap="4" align="start" className="w-full">
      <div className="h-[28rem]">
        <SideNav
          aria-label="Controlled navigation"
          collapsed={collapsed}
          onCollapsedChange={setCollapsed}
        >
          <SideNav.Header
            collapsedContent={
              <SideNav.Toggle>
                <ArrowRightIcon aria-hidden="true" className="rtl:rotate-180" />
              </SideNav.Toggle>
            }
          >
            <Text weight="bold">ZENOS</Text>
            <SideNav.Toggle>
              {collapsed ? (
                <ArrowRightIcon aria-hidden="true" className="rtl:rotate-180" />
              ) : (
                <ArrowLeftIcon aria-hidden="true" className="rtl:rotate-180" />
              )}
            </SideNav.Toggle>
          </SideNav.Header>
          <SideNav.Content>
            <SideNav.Section label="Workspace">
              <SideNav.Item active icon={<HouseIcon aria-hidden="true" />}>
                Overview
              </SideNav.Item>
              <SideNav.Item icon={<FolderIcon aria-hidden="true" />}>Projects</SideNav.Item>
            </SideNav.Section>
          </SideNav.Content>
        </SideNav>
      </div>
      <Button variant="primary" onClick={() => setCollapsed((value) => !value)}>
        {collapsed ? "Expand navigation" : "Collapse navigation"}
      </Button>
    </Stack>
  );
}
```

## Links and active state

`SideNav.Item` renders a button by default. Use `as="a"` with `href` for navigation, or another compatible semantic element. Set `active` only for the current destination; it adds `aria-current="page"` as well as the visual indicator.

Sections are expanded by default. Their `open`, `defaultOpen`, and `onOpenChange` props support controlled and uncontrolled disclosure state independently from the rail.

## Anatomy

```text
SideNav
SideNav.Header
SideNav.Content
SideNav.Section
SideNav.Item
SideNav.Footer
SideNav.Toggle
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| collapsed | boolean | — | Controlled rail state outside AppShell. |
| defaultCollapsed | boolean | false | Initial uncontrolled rail state. |
| onCollapsedChange | (collapsed: boolean) => void | — | Runs when rail state changes. |
| tooltip | boolean | true | Shows item-label tooltips while the navigation is collapsed. |
| as | ElementType | nav | Rendered element for Root, Header, Content, Section, Footer, and Item. Native props and ref types follow the selected element. |
| active | boolean | false | Marks SideNav.Item as the current page. |
| SideNav.Item icon | ReactNode | — | Visual icon retained when the navigation is collapsed. |
| SideNav.Header collapsedContent | ReactNode | — | Header content rendered in rail mode. |
| SideNav.Section label | ReactNode | — | Accessible section heading and disclosure trigger. |
| SideNav.Section open / defaultOpen | boolean | defaultOpen: true | Controlled or initial section disclosure state. |
| SideNav.Section onOpenChange | (open: boolean) => void | — | Runs when a section opens or closes. |
| SideNav.Toggle collapseLabel / expandLabel | string | — | Accessible labels for both toggle states. |
| native props | React.HTMLAttributes<HTMLElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Give each SideNav a concise `aria-label`. Provide a text equivalent for every icon through the item label; the same label supplies the collapsed tooltip. Tooltips also open on keyboard focus. Keep Toggle's default accessible labels unless the surrounding product language needs a clearer phrase. Section buttons expose their expanded state and remove collapsed content from keyboard interaction.

Source: https://zenos-ui.pages.dev/layout/side-nav/