Skip to content

Navigation

Sidebar

tsx
import { Sidebar, SidebarGroup, SidebarItem } from "@cherry-design-system/react";
import { House, Users } from "lucide-react";

export function AppSidebar() {
  return (
    <Sidebar navLabel="Main">
      <SidebarGroup label="Workspace">
        <SidebarItem href="/" icon={<House />} active>Home</SidebarItem>
        <SidebarItem href="/team" icon={<Users />}>Team</SidebarItem>
      </SidebarGroup>
    </Sidebar>
  );
}

Sidebar is the side navigation of an app: an <aside> with a header, a <nav> of SidebarGroups and a footer. It has no client JavaScript: collapsible groups are native <details>, the active item is plain aria-current, and collapsed is a prop you drive. For a top-of-page navigation use NavPill.

Examples

header and footer are slots for a logo, a workspace switcher, an account row or settings. badge puts a count or a Badge at the end of an item.

tsx
import { Badge, Sidebar, SidebarGroup, SidebarItem } from "@cherry-design-system/react";
import { Inbox, Settings } from "lucide-react";

export function AppSidebar() {
  return (
    <Sidebar header={<strong>Acme</strong>} footer={<span>Jane Doe</span>}>
      <SidebarGroup>
        <SidebarItem href="/inbox" icon={<Inbox />} badge={<Badge>12</Badge>}>
          Inbox
        </SidebarItem>
        <SidebarItem href="/settings" icon={<Settings />}>Settings</SidebarItem>
      </SidebarGroup>
    </Sidebar>
  );
}

Collapsible groups

collapsible turns the group title into a native disclosure. defaultOpen sets the initial state (open by default). A group needs a label to be collapsible.

tsx
import { Sidebar, SidebarGroup, SidebarItem } from "@cherry-design-system/react";

export function DocsSidebar() {
  return (
    <Sidebar navLabel="Docs">
      <SidebarGroup label="Guides" collapsible>
        <SidebarItem href="/installation">Installation</SidebarItem>
        <SidebarItem href="/theming">Theming</SidebarItem>
      </SidebarGroup>
      <SidebarGroup label="Archive" collapsible defaultOpen={false}>
        <SidebarItem href="/v1">Version 1</SidebarItem>
      </SidebarGroup>
    </Sidebar>
  );
}

Collapsed icon rail

collapsed hides labels, badges and group titles and eases the width to 64px. Icons stay visible. Hold the state in a Client Component and toggle it from a button in the header.

tsx
"use client";
import { useState } from "react";
import { IconButton, Sidebar, SidebarGroup, SidebarItem } from "@cherry-design-system/react";
import { House, PanelLeft, Users } from "lucide-react";

export function AppSidebar() {
  const [collapsed, setCollapsed] = useState(false);
  return (
    <Sidebar
      collapsed={collapsed}
      header={
        <IconButton
          aria-label={collapsed ? "Expand sidebar" : "Collapse sidebar"}
          aria-pressed={collapsed}
          icon={<PanelLeft />}
          variant="ghost"
          onClick={() => setCollapsed((value) => !value)}
        />
      }
    >
      <SidebarGroup label="Workspace">
        <SidebarItem href="/" icon={<House />}>Home</SidebarItem>
        <SidebarItem href="/team" icon={<Users />}>Team</SidebarItem>
      </SidebarGroup>
    </Sidebar>
  );
}

Button items

Without href a SidebarItem renders a <button>. Pass onClick from a Client Component; disabled works only in this form.

tsx
"use client";
import { SidebarItem } from "@cherry-design-system/react";
import { Plus } from "lucide-react";

export function NewProjectItem({ onCreate }: { onCreate: () => void }) {
  return (
    <SidebarItem icon={<Plus />} onClick={onCreate}>
      New project
    </SidebarItem>
  );
}

Properties

headerReactNode

Top slot: logo, workspace switcher, collapse button.

footerReactNode

Bottom slot: account, settings.

collapsedboolean

Icon rail: labels, badges and group titles hide, width eases to 64px.

navLabelstring

Names the navigation landmark. Defaults to "Sidebar".

Sidebar renders an <aside> with a <nav> inside, forwards its ref to the <aside> and passes other attributes through.

SidebarGroup

labelReactNode

Group title, rendered as an eyebrow. Optional.

collapsibleboolean

Makes the title a native disclosure that folds the group.

defaultOpenboolean

Initial state of a collapsible group. Defaults to open (true).

SidebarGroup renders a <div> (a <details> when collapsible), forwards its ref and passes other attributes through.

SidebarItem

iconReactNode

Leading icon, such as a lucide element. Stays visible when collapsed.

badgeReactNode

Trailing count or Badge.

activeboolean

Marks the current item (aria-current="page" on links, "true" on buttons).

disabledboolean

Only for the button form (no href).

SidebarItem renders an <li> holding an <a> (with href) or a <button> (without), forwards its ref to that element and passes other <a> attributes through. All parts are safe in Server Components.

Styling

HookValues
Classcherry-sidebar
Statesdata-collapsed, [aria-current="page"], [open], :disabled, :hover, :focus-visible
Partscherry-sidebar__header, cherry-sidebar__nav, cherry-sidebar__footer, cherry-sidebar__group, cherry-sidebar__group-label, cherry-sidebar__group-chevron, cherry-sidebar__list, cherry-sidebar__item, cherry-sidebar__link, cherry-sidebar__icon, cherry-sidebar__label, cherry-sidebar__badge

The panel reads --cherry-bg-subtle, --cherry-border-default, --cherry-ghost-hover and --cherry-radius-md.

Accessibility

The <nav> is a landmark named by navLabel. The active item is aria-current. When collapsed, items keep their names for screen readers and group titles leave the tab order. Icons are hidden from assistive tech, so every item needs text children.