suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Code Block
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Trace
  • Wheel Picker
  • Widget

suiss/ui · Component

Sidebar

A collapsible app sidebar for navigation, with icon, off-canvas and mobile sheet modes.

Sidebar is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.

import {
  CalendarBlankIcon,
  CaretUpDownIcon,
  ChartBarIcon,
  DotsThreeIcon,
  FolderIcon,
  GearIcon,
  HouseIcon,
  LifebuoyIcon,
  PlusIcon,
  TrayIcon,
  UsersIcon,
} from "@phosphor-icons/react"
import { Separator } from "@/components/ui/separator"
import {
  Sidebar,

SidebarProvider holds the open state and wraps the whole layout. Inside it, Sidebar renders the panel and SidebarInset renders the main content beside it. The sidebar stacks SidebarHeader, a scrolling SidebarContent and SidebarFooter. Content is organized into SidebarGroup sections, each with a SidebarGroupLabel, an optional SidebarGroupAction and a SidebarGroupContent. Navigation lives in a SidebarMenu of SidebarMenuItem rows, each holding a SidebarMenuButton and optionally a SidebarMenuAction, SidebarMenuBadge or nested SidebarMenuSub.

SidebarTrigger and SidebarRail toggle the sidebar. On screens narrower than 48rem, the sidebar renders inside a Sheet instead. Use Sidebar for the main navigation of an app; for bottom navigation on small screens, consider TabBar.

Installation

$ pnpm dlx shadcn@latest add @esuiss/sidebar

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add sidebar
  1. Install the following dependencies and add the cn helper:
$ pnpm add @base-ui/react @phosphor-icons/react class-variance-authority
  1. Add the pieces it builds on: Button, Direction, Input, Separator, Sheet, Skeleton, Tooltip, use-mobile, use-platform.

  2. Copy and paste the following code into your project.

components/ui/sidebar.tsx
"use client"

import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { SidebarIcon } from "@phosphor-icons/react"
import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"
import { Button } from "@/components/ui/button"
import { useDirection } from "@/components/ui/direction"
import { Input } from "@/components/ui/input"
import { Separator } from "@/components/ui/separator"
import {
  Sheet,
  SheetContent,
  SheetDescription,
  SheetHeader,
  1. Update the import paths to match your project setup.

Usage

import {
  Sidebar,
  SidebarContent,
  SidebarGroup,
  SidebarGroupContent,
  SidebarGroupLabel,
  SidebarHeader,
  SidebarInset,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarProvider,
  SidebarRail,
  SidebarTrigger,
} from "@/components/ui/sidebar"
<SidebarProvider>
  <Sidebar side="left" variant="sidebar" collapsible="icon">
    <SidebarHeader>Acme Inc.</SidebarHeader>
    <SidebarContent>
      <SidebarGroup>
        <SidebarGroupLabel>Platform</SidebarGroupLabel>
        <SidebarGroupContent>
          <SidebarMenu>
            {items.map((item) => (
              <SidebarMenuItem key={item.title}>
                <SidebarMenuButton isActive={item.active} tooltip={item.title}>
                  {item.icon}
                  <span>{item.title}</span>
                </SidebarMenuButton>
              </SidebarMenuItem>
            ))}
          </SidebarMenu>
        </SidebarGroupContent>
      </SidebarGroup>
    </SidebarContent>
    <SidebarRail />
  </Sidebar>
  <SidebarInset>
    <header className="flex h-14 items-center gap-2 border-b px-4">
      <SidebarTrigger />
    </header>
    <main className="p-4">{children}</main>
  </SidebarInset>
</SidebarProvider>

Examples

Floating

Set variant="floating" on Sidebar for a rounded panel with a shadow.

import {
  CalendarBlankIcon,
  CaretUpDownIcon,
  ChartBarIcon,
  DotsThreeIcon,
  FolderIcon,
  GearIcon,
  HouseIcon,
  LifebuoyIcon,
  PlusIcon,
  TrayIcon,
  UsersIcon,
} from "@phosphor-icons/react"
import { Separator } from "@/components/ui/separator"
import {
  Sidebar,

Inset

Set variant="inset" to also raise the main content into a rounded card.

import {
  CalendarBlankIcon,
  CaretUpDownIcon,
  ChartBarIcon,
  DotsThreeIcon,
  FolderIcon,
  GearIcon,
  HouseIcon,
  LifebuoyIcon,
  PlusIcon,
  TrayIcon,
  UsersIcon,
} from "@phosphor-icons/react"
import { Separator } from "@/components/ui/separator"
import {
  Sidebar,

Collapsed

Set collapsible="icon" and defaultOpen={false} to start collapsed to a rail of icons. Click the rail to expand it. Give each SidebarMenuButton a tooltip so its label stays available while collapsed.

import {
  CalendarBlankIcon,
  CaretUpDownIcon,
  ChartBarIcon,
  DotsThreeIcon,
  FolderIcon,
  GearIcon,
  HouseIcon,
  LifebuoyIcon,
  PlusIcon,
  TrayIcon,
  UsersIcon,
} from "@phosphor-icons/react"
import { Separator } from "@/components/ui/separator"
import {
  Sidebar,

Offcanvas

Set collapsible="offcanvas" to slide the sidebar fully out of view when collapsed.

import {
  CalendarBlankIcon,
  CaretUpDownIcon,
  ChartBarIcon,
  DotsThreeIcon,
  FolderIcon,
  GearIcon,
  HouseIcon,
  LifebuoyIcon,
  PlusIcon,
  TrayIcon,
  UsersIcon,
} from "@phosphor-icons/react"
import { Separator } from "@/components/ui/separator"
import {
  Sidebar,

Right side

Set side="right" to place the sidebar on the right edge.

import {
  CalendarBlankIcon,
  CaretUpDownIcon,
  ChartBarIcon,
  DotsThreeIcon,
  FolderIcon,
  GearIcon,
  HouseIcon,
  LifebuoyIcon,
  PlusIcon,
  TrayIcon,
  UsersIcon,
} from "@phosphor-icons/react"
import { Separator } from "@/components/ui/separator"
import {
  Sidebar,

Loading

Show SidebarMenuSkeleton placeholders while items load. Set showIcon to add a square placeholder for an icon.

import { Separator } from "@/components/ui/separator"
import {
  Sidebar,
  SidebarContent,
  SidebarGroup,
  SidebarGroupContent,
  SidebarGroupLabel,
  SidebarHeader,
  SidebarInset,
  SidebarMenu,
  SidebarMenuItem,
  SidebarMenuSkeleton,
  SidebarProvider,
  SidebarTrigger,
} from "@/components/ui/sidebar"

Accessibility

  • SidebarTrigger and SidebarRail are labelled Toggle Sidebar. The rail is removed from the tab order, so keep a SidebarTrigger in reach of keyboard users.
  • Press Command-B on Apple platforms, or Ctrl+B elsewhere, to toggle the sidebar.
  • On mobile, the sidebar is a dialog with a visually hidden title, Sidebar; Escape closes it.
  • Menu-button tooltips appear only while the sidebar is collapsed, so labels stay available when only icons show.

API Reference

SidebarProvider

Holds the open state, provides it through context and wraps the layout.

PropTypeDefault
defaultOpenbooleantrue
openboolean-
onOpenChange(open: boolean) => void-

Also accepts the props of React.ComponentProps<"div">.

Use defaultOpen for an uncontrolled sidebar, or open with onOpenChange to control it. Every toggle writes the state to a sidebar_state cookie for 7 days; read it on the server to set defaultOpen and avoid a flash on load. Widths come from --sidebar-width (16rem) and --sidebar-width-icon (3rem), set on SidebarProvider; override them through its style.

Read and change the state from any child with the useSidebar hook, which returns state, open, setOpen, openMobile, setOpenMobile, isMobile and toggleSidebar. It throws when used outside a SidebarProvider.

Sidebar

The sidebar panel; a sheet on mobile.

PropTypeDefault
side"left" | "right""left"
variant"sidebar" | "floating" | "inset""sidebar"
collapsible"offcanvas" | "icon" | "none""offcanvas"

Also accepts the props of React.ComponentProps<"div">.

variant chooses a full-height sidebar, a rounded floating panel or an inset layout. Set collapsible="icon" to shrink the sidebar to a rail of icons when collapsed, offcanvas to slide it out of view, or none to keep it fixed. On screens narrower than 48rem the sidebar renders inside a Sheet. The sidebar element sets data-state (expanded or collapsed), data-collapsible, data-variant and data-side for styling. The panel uses the sidebar-* color variables; change them to style it apart from the page.

SidebarTrigger

An icon button that toggles the sidebar.

Also accepts the props of React.ComponentProps<typeof Button>.

SidebarRail

A thin hit area along the sidebar's edge that toggles it on click.

Also accepts the props of React.ComponentProps<"button">.

SidebarInset

The main element for page content next to the sidebar.

Also accepts the props of React.ComponentProps<"main">.

SidebarInput

A compact Input styled for use in the sidebar.

Also accepts the props of React.ComponentProps<typeof Input>.

SidebarHeader

The top area, above the scrolling content.

Also accepts the props of React.ComponentProps<"div">.

SidebarFooter

The bottom area, below the scrolling content.

Also accepts the props of React.ComponentProps<"div">.

SidebarSeparator

A divider between sidebar sections.

Also accepts the props of React.ComponentProps<typeof Separator>.

SidebarContent

The scrolling region that holds the groups.

Also accepts the props of React.ComponentProps<"div">.

SidebarGroup

A section of related content.

Also accepts the props of React.ComponentProps<"div">.

SidebarGroupLabel

The title of a group; it fades out when collapsed to icons.

Also accepts the props of useRender.ComponentProps<"div">, React.ComponentProps<"div">.

Also accepts the props of React.ComponentProps<"div">, plus asChild.

Also accepts the props of React.ComponentProps<"div">, plus a render function.

SidebarGroupAction

A small button in the corner of a group, such as an add button.

Also accepts the props of useRender.ComponentProps<"button">, React.ComponentProps<"button">.

Also accepts the props of React.ComponentProps<"button">, plus asChild.

Also accepts the props of React.ComponentProps<"button">, plus a render function.

SidebarGroupContent

The body of a group.

Also accepts the props of React.ComponentProps<"div">.

SidebarMenu

A list of menu items.

Also accepts the props of React.ComponentProps<"ul">.

SidebarMenuItem

A list item that holds a menu button and its extras.

Also accepts the props of React.ComponentProps<"li">.

SidebarMenuButton

The clickable row for a destination or command.

PropTypeDefault
isActivebooleanfalse
tooltipstring | React.ComponentProps<typeof TooltipContent>-
variant"default" | "outline""default"
size"default" | "sm" | "lg""default"

Also accepts the props of useRender.ComponentProps<"button">, React.ComponentProps<"button">.

Use the render prop to render the button as a link.

Also accepts the props of React.ComponentProps<"button">, plus asChild.

Set asChild and pass a link as the child to render the button as a link.

Also accepts the props of React.ComponentProps<"button">, plus a render function.

Pass a render function that returns a link with the props it receives to render the button as a link.

isActive marks the current item. tooltip takes text or TooltipContent props for a tooltip shown only while collapsed on desktop. The outline variant adds a background and border, and size sets the row height. Menu buttons set data-active and data-size.

SidebarMenuAction

A small button at the end of a menu item, such as a more button.

PropTypeDefault
showOnHoverbooleanfalse

On desktop, showOnHover hides the action until its item is hovered or focused.

Also accepts the props of useRender.ComponentProps<"button">, React.ComponentProps<"button">.

Also accepts the props of React.ComponentProps<"button">, plus asChild.

Also accepts the props of React.ComponentProps<"button">, plus a render function.

SidebarMenuBadge

A count or label shown at the end of a menu item.

Also accepts the props of React.ComponentProps<"div">.

SidebarMenuSkeleton

A loading placeholder shaped like a menu item.

PropTypeDefault
showIconbooleanfalse

Also accepts the props of React.ComponentProps<"div">.

SidebarMenuSub

A nested list of sub-items, indented with a leading line.

Also accepts the props of React.ComponentProps<"ul">.

SidebarMenuSubItem

A list item inside a sub-menu.

Also accepts the props of React.ComponentProps<"li">.

SidebarMenuSubButton

The clickable row of a sub-item, rendered as a link by default.

PropTypeDefault
size"sm" | "md""md"
isActivebooleanfalse

size sets the text size, and isActive marks the sub-item as the current page.

Also accepts the props of useRender.ComponentProps<"a">, React.ComponentProps<"a">.

Also accepts the props of React.ComponentProps<"a">, plus asChild.

Also accepts the props of React.ComponentProps<"a">, plus a render function.

NextSignature PadPreviousSheet

On this page

  1. 01Installation
  2. 02Usage
  3. 03Examples
    • Floating
    • Inset
    • Collapsed
    • Offcanvas
    • Right side
    • Loading
  4. 04Accessibility
  5. 05API Reference
    • SidebarProvider
    • Sidebar
    • SidebarTrigger
    • SidebarRail
    • SidebarInset
    • SidebarInput
    • SidebarHeader
    • SidebarFooter
    • SidebarSeparator
    • SidebarContent
    • SidebarGroup
    • SidebarGroupLabel
    • SidebarGroupAction
    • SidebarGroupContent
    • SidebarMenu
    • SidebarMenuItem
    • SidebarMenuButton
    • SidebarMenuAction
    • SidebarMenuBadge
    • SidebarMenuSkeleton
    • SidebarMenuSub
    • SidebarMenuSubItem
    • SidebarMenuSubButton