

<Demo name="sidebar/demos/basic" />

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/sidebar
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/sidebar
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/sidebar
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun x shadcn@latest add @dotui/sidebar
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Anatomy [#anatomy]

A sidebar is built from a `SidebarProvider` wrapping the `Sidebar` and a `SidebarInset` (the main content). Inside the sidebar, compose a header, scrollable content split into groups of menus, and a footer.

```tsx
import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarGroup,
  SidebarGroupLabel,
  SidebarHeader,
  SidebarInset,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarProvider,
  SidebarTrigger,
} from '@/components/ui/sidebar'
```

```tsx
<SidebarProvider>
  <Sidebar>
    <SidebarHeader />
    <SidebarContent>
      <SidebarGroup>
        <SidebarGroupLabel>Platform</SidebarGroupLabel>
        <SidebarMenu>
          <SidebarMenuItem>
            <SidebarMenuButton>Dashboard</SidebarMenuButton>
          </SidebarMenuItem>
        </SidebarMenu>
      </SidebarGroup>
    </SidebarContent>
    <SidebarFooter />
  </Sidebar>
  <SidebarInset>
    <SidebarTrigger />
    {/* page content */}
  </SidebarInset>
</SidebarProvider>
```

## Usage [#usage]

The `Sidebar` positions itself relative to the `SidebarProvider`, so the whole shell is self-contained. For a full-screen app, give the provider the viewport height and let the content scroll inside the inset:

```tsx
<SidebarProvider className="h-svh">
  <Sidebar>{/* ... */}</Sidebar>
  <SidebarInset className="overflow-auto">{/* ... */}</SidebarInset>
</SidebarProvider>
```

Below the `md` breakpoint the sidebar renders as an off-canvas drawer, toggled by the same `SidebarTrigger`. The sidebar can also be toggled from anywhere with <kbd>⌘</kbd>+<kbd>B</kbd> (<kbd>Ctrl</kbd>+<kbd>B</kbd>).

### Links [#links]

Pass `href` to `SidebarMenuButton` (or `SidebarMenuSubButton`) to render it as a link, and `isActive` to mark the current page (which also sets `aria-current="page"`).

```tsx
<SidebarMenuButton href="/dashboard" isActive>
  <HomeIcon />
  <span>Dashboard</span>
</SidebarMenuButton>
```

### useSidebar [#usesidebar]

Read or control the sidebar state from any descendant of `SidebarProvider`:

```tsx
const {
  state,
  isOpen,
  setOpen,
  isMobile,
  openMobile,
  setOpenMobile,
  toggleSidebar,
} = useSidebar()
```

### Controlled state [#controlled-state]

Drive the open state yourself with `isOpen` and `onOpenChange` on `SidebarProvider` — useful for persisting it (e.g. in a cookie or `localStorage`).

## Examples [#examples]

<Examples>
  <Example name="sidebar/demos/collapsible-icon" />

  <Example name="sidebar/demos/floating" />

  <Example name="sidebar/demos/inset" />

  <Example name="sidebar/demos/right" />

  <Example name="sidebar/demos/groups" />

  <Example name="sidebar/demos/submenu" />

  <Example name="sidebar/demos/badges-and-actions" />

  <Example name="sidebar/demos/search" />

  <Example name="sidebar/demos/footer-user" />

  <Example name="sidebar/demos/loading" />

  <Example name="sidebar/demos/rail" />

  <Example name="sidebar/demos/controlled" />
</Examples>

## API Reference [#api-reference]

### SidebarProvider [#sidebarprovider]

<Reference name="sidebar-provider" />

### Sidebar [#sidebar]

<Reference name="sidebar" />

### SidebarInset [#sidebarinset]

<Reference name="sidebar-inset" />

### SidebarTrigger [#sidebartrigger]

<Reference name="sidebar-trigger" />

### SidebarRail [#sidebarrail]

<Reference name="sidebar-rail" />

### SidebarHeader [#sidebarheader]

<Reference name="sidebar-header" />

### SidebarFooter [#sidebarfooter]

<Reference name="sidebar-footer" />

### SidebarContent [#sidebarcontent]

<Reference name="sidebar-content" />

### SidebarSeparator [#sidebarseparator]

<Reference name="sidebar-separator" />

### SidebarGroup [#sidebargroup]

<Reference name="sidebar-group" />

### SidebarGroupLabel [#sidebargrouplabel]

<Reference name="sidebar-group-label" />

### SidebarGroupAction [#sidebargroupaction]

<Reference name="sidebar-group-action" />

### SidebarGroupContent [#sidebargroupcontent]

<Reference name="sidebar-group-content" />

### SidebarMenu [#sidebarmenu]

<Reference name="sidebar-menu" />

### SidebarMenuItem [#sidebarmenuitem]

<Reference name="sidebar-menu-item" />

### SidebarMenuButton [#sidebarmenubutton]

<Reference name="sidebar-menu-button" />

### SidebarMenuAction [#sidebarmenuaction]

<Reference name="sidebar-menu-action" />

### SidebarMenuBadge [#sidebarmenubadge]

<Reference name="sidebar-menu-badge" />

### SidebarMenuSkeleton [#sidebarmenuskeleton]

<Reference name="sidebar-menu-skeleton" />

### SidebarMenuSub [#sidebarmenusub]

<Reference name="sidebar-menu-sub" />

### SidebarMenuSubItem [#sidebarmenusubitem]

<Reference name="sidebar-menu-sub-item" />

### SidebarMenuSubButton [#sidebarmenusubbutton]

<Reference name="sidebar-menu-sub-button" />
