Sidebar
Installation
Add the component with the CLI.
npx shadcn@latest add @intentui/sidebar
Composed components
When you install this component via the CLI, it automatically loads all composed components, so you don’t need to add them individually.
Manual installation
Install the dependencies, then copy the component source into your project.
npm install react-aria-components @heroicons/react cn
CSS variables
The sidebar derives its accent from a base color and uses your theme’s primary color. Add the default variables below to your stylesheet, or choose colors on the theme page.
@theme inline {
--color-sidebar: var(--sidebar);
--color-sidebar-fg: var(--sidebar-fg);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-accent-fg: var(--sidebar-accent-fg);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-ring: var(--sidebar-ring);
}
:root {
--sidebar: oklch(0.985 0 0);
--sidebar-fg: oklch(0.141 0.005 285.823);
--sidebar-primary: oklch(0.623 0.214 259.815 / 0.15);
--sidebar-primary-foreground: oklch(0.488 0.243 264.376);
--sidebar-accent: oklch(0.92 0.004 286.32);
--sidebar-accent-fg: oklch(0.141 0.005 285.823);
--sidebar-border: oklch(0.901 0.006 286.286);
--sidebar-ring: oklch(0.546 0.245 262.881);
}
.dark {
--sidebar: oklch(0.21 0.006 285.885);
--sidebar-fg: oklch(0.985 0 0);
--sidebar-primary: oklch(0.623 0.214 259.815 / 0.1);
--sidebar-primary-foreground: oklch(0.707 0.165 254.624);
--sidebar-accent: oklch(0.274 0.006 286.033);
--sidebar-accent-fg: oklch(0.985 0 0);
--sidebar-border: oklch(0.274 0.006 286.033);
--sidebar-ring: oklch(0.546 0.245 262.881);
}See theme customization to adjust the colors.
Examples
Intent
The sidebar comes in three variations: sidebar, float, and inset. By default, the variation is set to "sidebar".
Default
The default variation is a traditional sidebar often used for navigation. Preview.
<Sidebar intent="default" />Inset
The inset variation adds padding to the main content for a visually distinct layout. Explore the demo to see it in action, or switch to full-screen mode for a better view. Preview.
<Sidebar intent="inset" />Float
The float variation introduces an inner border within the sidebar, while the wrapper includes padding around the content. Preview
<Sidebar intent="float" />Collapsible
The sidebar can be made collapsible by using the collapsible prop in the SidebarProvider. The default collapsible behavior is hidden.
Hidden
When toggled, the sidebar hides completely from view. Preview
<Sidebar collapsible="hidden" />Dock
When toggled, the sidebar docks to a minimal state, showing only icons. Hovering over an icon reveals a tooltip with additional information. Preview
<Sidebar intent="dock" />Default open
Set defaultOpen={false} to start with the sidebar closed. Its closed appearance depends on the collapsible mode.
<SidebarProvider defaultOpen={false}>
<Sidebar collapsible="dock" />Sidebar section
The sidebar section is a container for sidebar items. It accepts a label prop, which will be displayed as a heading.
<SidebarSection>
<SidebarItem isCurrent href="#">
<SidebarLabel>Item 1</SidebarLabel>
</SidebarItem>
</SidebarSection>
<SidebarSection label="Other Section">
<SidebarItem isCurrent href="#">
<SidebarLabel>Item 1</SidebarLabel>
</SidebarItem>
</SidebarSection>Sidebar disclosure group
If you need to collapse multiple items, you can use the SidebarDisclosureGroup component. Preview
<SidebarDisclosureGroup defaultExpandedKeys={[1]}>
<SidebarDisclosure id={1}>
<SidebarDisclosureTrigger>
<EllipsisHorizontalIcon />
<SidebarLabel>Support</SidebarLabel>
</SidebarDisclosureTrigger>
<SidebarDisclosurePanel>
<SidebarItem href="#" tooltip="Tickets">
<TicketIcon />
<SidebarLabel>Tickets</SidebarLabel>
</SidebarItem>
<SidebarItem href="#" tooltip="Chat Support">
<ChatBubbleLeftRightIcon />
<SidebarLabel>Chat Support</SidebarLabel>
</SidebarItem>
<SidebarItem href="#" tooltip="FAQ">
<QuestionMarkCircleIcon />
<SidebarLabel>FAQ</SidebarLabel>
</SidebarItem>
<SidebarItem href="#" tooltip="Documentation">
<DocumentTextIcon />
<SidebarLabel>Documentation</SidebarLabel>
</SidebarItem>
</SidebarDisclosurePanel>
</SidebarDisclosure>
<SidebarDisclosure id={2}>
<SidebarDisclosureTrigger>
<ArchiveBoxIcon />
<SidebarLabel>Inventory</SidebarLabel>
</SidebarDisclosureTrigger>
<SidebarDisclosurePanel>
<SidebarItem href="#" tooltip="Warehouse">
<BuildingOfficeIcon />
<SidebarLabel>Warehouse</SidebarLabel>
</SidebarItem>
<SidebarItem href="#" tooltip="Stock Levels">
<SidebarLabel>Stock Levels</SidebarLabel>
</SidebarItem>
<SidebarItem href="#" tooltip="Shipping">
<SidebarLabel>Shipping</SidebarLabel>
</SidebarItem>
</SidebarDisclosurePanel>
</SidebarDisclosure>
</SidebarDisclosureGroup>Tree
Use SidebarTree, SidebarTreeItem, and SidebarTreeContent to build hierarchical navigation. Preview.
Menu actions
The sidebar supports menus for displaying additional actions or options.
<SidebarItem tooltip="Orders">
{({ isCollapsed, isFocused }) => (
<>
<SidebarLink href="#">
<SidebarLabel>Orders</SidebarLabel>
</SidebarLink>
{(!isCollapsed || isFocused) && (
<MenuTrigger>
<SidebarMenuTrigger aria-label="Manage">
<EllipsisHorizontalIcon />
</SidebarMenuTrigger>
<Menu popover={{ offset: 0, placement: "right top" }}>
<MenuItem href="#new-order">
<PlusIcon />
Create New Order
</MenuItem>
<MenuItem href="#view-all">
View All Orders
</MenuItem>
<MenuItem href="#pending-orders">
Pending Orders
</MenuItem>
<MenuItem href="#completed-orders">
Completed Orders
</MenuItem>
<MenuItem href="#export-orders">
Export Orders
</MenuItem>
</Menu>
</MenuTrigger>
)}
</>
)}
</SidebarItem>By default, the sidebar menu trigger will be visible when you hover over the sidebar item. If you want to always show the menu trigger, you can use the alwaysVisible prop.
<SidebarMenuTrigger alwaysVisible aria-label="Manage">
<EllipsisHorizontalIcon />
</SidebarMenuTrigger>Badge
The sidebar supports badges, which can be used to indicate the number of unread messages, tasks, or other items. Preview
<SidebarSection>
{navigation.map((item, index) => (
<SidebarItem key={index} isCurrent={item.isCurrent} href="#">
{item.icon}
<SidebarLabel>{item.label}</SidebarLabel>
{item.badge != null && <SidebarBadge>{item.badge}</SidebarBadge>}
</SidebarItem>
))}
</SidebarSection>
const navigation = [
{ label: "Overview", icon: <HomeIcon />, isCurrent: true, badge: undefined },
{ label: "Products", icon: <CubeIcon />, isCurrent: false, badge: "31.51K" },
]Separator
The sidebar supports separators, which can be used to separate sections or groups of items. Preview
<SidebarContent>
<SidebarSection/>
<SidebarSeparator />
<SidebarSection/>
<SidebarSection/>
<SidebarSeparator />
<SidebarSectionGroup/>
<SidebarSectionGroup/>
<SidebarSeparator />
<SidebarSectionGroup/>
</SidebarContent>The example previews will appear similar to the ones in the YouTube sidebar.
Tooltip
The sidebar supports tooltips, which can be used to display additional information when you're on docked mode.
Header
The sidebar supports headers, which can be used to display additional actions or options.
<Sidebar {...props}>
<SidebarHeader>
<Link
className="flex items-center group-data-[collapsible=dock]:size-10 group-data-[collapsible=dock]:justify-center gap-x-2"
href="/docs/components/layouts/sidebar"
>
<SidebarLabel className="font-medium">Intent UI</SidebarLabel>
</Link>
</SidebarHeader>
...
</Sidebar>Footer
The sidebar supports footers, which can be used to display additional actions or options.
<Sidebar {...props}>
...
<SidebarFooter>
<MenuTrigger>
<Button aria-label="Profile">
<Avatar isSquare src="https://intentui.com/images/avatar/cobain.jpg" />
<div className="group-data-[collapsible=dock]:hidden text-sm">
Kurt Cobain
<span className="block -mt-0.5 text-muted-foreground">@cobain</span>
</div>
<ChevronDownIcon className="absolute right-3 transition-transform size-4 group-pressed:rotate-180" />
</Button>
<Menu placement="bottom right" className="min-w-(--trigger-width)">
<MenuItem/>
</Menu>
</MenuTrigger>
</SidebarFooter>
</Sidebar>Side
The sidebar has two sides, left and right. You can set the side of the sidebar by using the side prop. Preview
<Sidebar side='left | right'/>Put anything
Wrap custom content in SidebarContent. This example adds a range calendar and a search field. Preview
Remember state
To persist the sidebar’s state across sessions, wrap your layout with the SidebarProvider component. It stores the sidebar’s state in a cookie and restores it when the user revisits the page.
import { cookies } from "next/headers"
export default async function Layout({ children }: Readonly<{ children: React.ReactNode }>) {
const cookieStore = await cookies()
const sidebarState = cookieStore.get("sidebar_state")
let defaultOpen = true
if (sidebarState) {
defaultOpen = sidebarState.value === "true"
}
return (
<SidebarProvider defaultOpen={defaultOpen}>Component API
Sidebar
Sidebar extends the native <div> element.
classNamestringcloseButtonbooleantruecollapsible"hidden" | "dock" | "none"hiddenintent"default" | "float" | "inset"defaultside"left" | "right"leftSidebarContent
SidebarContent extends the native <div> element.
classNamestringSidebarDisclosure
SidebarDisclosure extends the React Aria Components <Disclosure> component.
classNamestringSidebarDisclosureGroup
SidebarDisclosureGroup extends the React Aria Components <DisclosureGroup> component.
classNamestringSidebarDisclosurePanel
SidebarDisclosurePanel extends the React Aria Components <DisclosurePanel> component.
classNamestringSidebarDisclosureTrigger
SidebarDisclosureTrigger extends the React Aria Components <Button> component.
classNamestringSidebarFooter
SidebarFooter extends the native <div> element.
classNamestringSidebarHeader
SidebarHeader extends the native <div> element.
classNamestringSidebarInset
SidebarInset extends the native <main> element.
classNamestringSidebarItem
SidebarItem extends the Intent UI <Link> component.
badgestring | number | undefinedclassNamestringisCurrentbooleantooltipstring | React.ComponentProps<typeof TooltipContent>SidebarLabel
SidebarLabel extends the React Aria Components <Text> component.
classNamestringSidebarLink
SidebarLink extends the React Aria Components <Link> component.
classNamestringSidebarMenuTrigger
SidebarMenuTrigger extends the React Aria Components <Button> component.
alwaysVisiblebooleanfalseclassNamestringSidebarNav
SidebarNav extends the native <nav> element.
classNamestringisStickybooleanfalseSidebarProvider
SidebarProvider extends the native <div> element.
classNamestringdefaultOpenbooleantrueisOpenbooleanonOpenChange(open: boolean) => voidshortcutstringbSidebarRail
SidebarRail extends the native <button> element.
classNamestringSidebarSection
SidebarSection extends the native <div> element.
classNamestringlabelstringSidebarSectionGroup
SidebarSectionGroup extends the native <section> element.
classNamestringSidebarSeparator
SidebarSeparator extends the React Aria Components <Separator> component.
classNamestringSidebarTree
SidebarTree extends the React Aria Components <Tree> component.
classNamestringSidebarTreeContent
SidebarTreeContent extends the React Aria Components <TreeItemContent> component.
classNamestringisCurrentbooleanSidebarTreeItem
SidebarTreeItem extends the React Aria Components <TreeItem> component.
classNamestringSidebarTrigger
SidebarTrigger extends the Intent UI <Button> component.
classNamestring