Demos

A static sidebar with a header, a labelled group of links, a badge, and a footer.

Usage

Use the sidebar for the main navigation of an app with several top-level sections. Wrap the layout in SidebarProvider and put the page in SidebarInset. On mobile the sidebar opens as a Sheet.

Import it from @workspace/ui/components/sidebar.

Anatomy

  • SidebarProvider — Holds the open state and handles the Cmd/Ctrl + B shortcut.
  • Sidebar — The panel. Sets side, variant, and how it collapses.
  • SidebarHeader and SidebarFooter — Fixed areas at the top and bottom.
  • SidebarContent — The scrolling middle.
  • SidebarInput — A compact search field for the header.
  • SidebarSeparator — A line between groups.
  • SidebarGroup, SidebarGroupLabel, SidebarGroupContent — A labelled section.
  • SidebarGroupAction — A small button in the corner of a group, such as "Add".
  • SidebarMenu, SidebarMenuItem, SidebarMenuButton — The list of items. Buttons by default.
  • SidebarMenuBadge, SidebarMenuAction — A count and a trailing button on an item.
  • SidebarMenuSub, SidebarMenuSubItem, SidebarMenuSubButton — Nested links. The sub button renders an anchor.
  • SidebarMenuSkeleton — A loading row for a menu.
  • SidebarTrigger — A button that toggles the sidebar.
  • SidebarRail — A thin edge strip that toggles the sidebar on click.
  • SidebarInset — The main content area next to the sidebar.
  • useSidebar — Hook that returns state, open, setOpen, openMobile, setOpenMobile, isMobile, and toggleSidebar.

Notes

  • The open state is written to the sidebar_state cookie. Read it on the server and pass it to defaultOpen to keep the state across reloads.
  • With collapsible="icon", set tooltip on each SidebarMenuButton so the label is still available when only the icon shows.
  • Mark the current page with isActive.
  • To render a link, pass an anchor through render on SidebarMenuButton.

Examples

Groups

Split links into labelled groups with SidebarSeparator between them.

Nest links under an item with SidebarMenuSub.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

SidebarProvider

PropTypeDefaultDescription
defaultOpenbooleantrueOpen on first render.
openboolean—Open state when controlled.
onOpenChange(open) => void—Called when the state changes.
PropTypeDefaultDescription
side"left" or "right"leftEdge of the screen.
variant"sidebar", "floating", or "inset"sidebarVisual style.
collapsible"offcanvas", "icon", or "none"offcanvasHow the sidebar collapses.

SidebarMenuButton

PropTypeDefaultDescription
isActivebooleanfalseMarks the current page.
variant"default" or "outline"defaultVisual style.
size"default", "sm", or "lg"defaultHeight of the button.
tooltipstring or TooltipContent props—Shown when the sidebar is collapsed to icons.
renderReactElement—Element to render instead of a button.

SidebarMenuAction

PropTypeDefaultDescription
showOnHoverbooleanfalseHide the action until the item is hovered or focused.

SidebarMenuSubButton

PropTypeDefaultDescription
isActivebooleanfalseMarks the current page.
size"sm" or "md"mdSize of the link.
renderReactElement—Element to render instead of an anchor.

SidebarMenuSkeleton

PropTypeDefaultDescription
showIconbooleanfalseShow an icon placeholder before the text.