Skip to content

Sidebar

Shows app navigation that collapses to an icon rail.

Overview

Revenue this month

$48,210

+12.4% from August

Latest orders

  • Olivia Martin#3210$1,999
  • Jackson Lee#3209$39
  • Isabella Nguyen#3208$299
sidebar-demo.tsx

Installation

The CLI adds the files, packages, theme variables, and Tailwind plugin that this component uses. Before you run it, set up your project.

Usage

app-shell.tsx

Composition

  • SidebarProvider

    Owns the collapsed state and the sheet state.

    • Sidebar
      • SidebarHeaderOptional
      • SidebarContent
        • SidebarGroupRepeats
          • SidebarGroupLabelOptional
          • SidebarMenu
            • SidebarItemRepeats
      • SidebarFooterOptional
    • SidebarInset
      • SidebarTrigger

        Put it in the inset header so it stays visible in the rail and on phones.

useSidebar Returns isOpen, setOpen, toggle, isMobileOpen, setMobileOpen, and state for a custom trigger.

Collapsed rail

Set defaultOpen to false to start as a rail.

Projects

Studio North

Maya Chen

Due Oct 18

Atlas

Sam Rivera

Due Oct 24

Field Notes

Jo Park

Due Nov 2

Signal

Maya Chen

Due Nov 9

sidebar-rail-demo.tsx

Sections and badges

Also install Badge.

Overview

Today

  • 12 orders need a shipping label
  • 3 payouts are due on Friday
  • 2 customers asked about the return policy
sidebar-sections-demo.tsx

Mobile sheet

Below 48rem of container width, the sidebar opens in a sheet.

Overview

Olivia Martin

#3210 · $1,999

Jackson Lee

#3209 · $39

Isabella Nguyen

#3208 · $299

sidebar-mobile-demo.tsx

Keyboard shortcut

Mod+B toggles the sidebar. Set shortcut to false to turn it off. Also install Kbd & code.

CtrlB

Recent orders

Olivia Martin#3210$1,999
Jackson Lee#3209$39
Isabella Nguyen#3208$299
sidebar-shortcut-demo.tsx

API reference

SidebarProvider

Lays out the sidebar and the page area, and owns the collapsed state and the sheet state.

isOpen: boolean
Controls the collapsed state.
defaultOpen: boolean = true
Opens the wide sidebar at first. Set it to false to start as a rail.
onOpenChange: (isOpen: boolean) => void
Receives the new collapsed state. Use it to save the state in a cookie or a parent.
shortcut: boolean = true
Toggles the sidebar with Mod+B. The shortcut does not fire in a field or while an event is already handled.
--sidebar-width: CSS length = 16rem
Sets the width of the expanded sidebar. Set it on the provider.
--sidebar-width-rail: CSS length = 3.5rem
Sets the width of the rail. Set it on the provider.

Sidebar

collapsible: "icon" | "none" = "icon"
Sets icon to collapse to a rail, or none to keep the sidebar at full width.
aria-label: string = "Sidebar"
Names the navigation landmark.

SidebarMenu

aria-label: string
Names the nav landmark. Set it when the sidebar has more than one menu.

SidebarHeader

Holds the brand and the trigger at the top of the sidebar.

SidebarContent

The scrolling middle of the sidebar. It fades the top and bottom edges.

SidebarFooter

Holds account or version content at the bottom. It hides in the rail unless a child sets data-rail="keep".

SidebarGroup

Groups items under a label.

aria-label: string
Names the group when it has no SidebarGroupLabel.
aria-labelledby: string
Points to the label element. The group uses its SidebarGroupLabel by default.

SidebarGroupLabel

Names a group. It becomes screen-reader-only in the rail so the icon items keep their context.

SidebarItem

href: stringRequired
The link target.
icon: ReactNodeRequired
The icon before the label. It uses an 18px size and fills when isCurrent is set.
isCurrent: boolean = false
Marks the current page with aria-current="page" and the accent fill.
badge: ReactNode
A badge after the label. In the rail it shrinks to a 6px dot, and the text stays in the accessible name.
tooltip: string
The rail tooltip text. Without it, a string label is the text.
onPress: (event: PressEvent) => void
Runs on press. In the mobile sheet, the sheet closes after it.

SidebarInset

render: (props, state) => ReactElement
Renders a different element, such as main. The state argument is expanded or collapsed.

SidebarTrigger

Toggles the rail in the wide layout, and opens the sheet in the narrow layout. Accepts Button props for variant and size.

aria-label: string
Names the button. The default is "Collapse sidebar", "Expand sidebar", or "Open navigation".