Sidebar
A composable, themeable and customizable sidebar component.
Installation
Anatomy
<SidebarProvider>
<Sidebar>
<SidebarClose />
<SidebarHeader>{/* Your sidebar header */}</SidebarHeader>
<SidebarContent>{/* Your sidebar content */}</SidebarContent>
<SidebarFooter>{/* Your sidebar footer */}</SidebarFooter>
<SidebarRail />
</Sidebar>
<SidebarInset>{/* Your main content */}</SidebarInset>
</SidebarProvider>Examples
Notion Sidebar
API Reference
SidebarProvider
| Prop | Type | Default | Description |
|---|---|---|---|
config | Partial<SidebarConfig> | - | The configuration object of the sidebar. |
defaultOpen | boolean | - | The open state of the sidebar when it is initially rendered. Use when you do not need to control its open state. |
open | boolean | - | The (controlled) open state of the sidebar. Must be used in conjunction with onOpenChange. |
onOpenChange | (open: boolean) => void | - | Handler that is called when the open state of the sidebar changes. |
Note
All the layout components below must be used within <SidebarProvider>.
Sidebar
A Sidebar extends the HTML <div> element. We list the extended properties only.
| Prop | Type | Default | Description |
|---|---|---|---|
side | "left" | "right" | "left" | The side of the sidebar. |
variant | "sidebar" | "floating" | "sidebar" | The variant of the sidebar. |
collapsible | "offcanvas" | "none" | "offcanvas" | Collapsible state of the sidebar. |
SidebarHeader
A SidebarHeader extends the HTML <div> element.
SidebarContent
A SidebarContent extends the HTML <div> element.
SidebarFooter
A SidebarFooter extends the HTML <div> element.
SidebarGroup
A SidebarGroup extends the HTML <div> element.
SidebarInset
A SidebarInset extends the HTML <main> element.
SidebarRail
The SidebarRail is used to render a rail within a <Sidebar>. This rail can be used to toggle and resize the sidebar.
It extends the HTML <div> element. We list the extended properties only.
| Prop | Type | Default | Description |
|---|---|---|---|
enableDrag | boolean | true | Whether the sidebar is draggable. |
SidebarClose
The SidebarClose is used to close the sidebar. It can be triggered by keyboard shortcut.
It extends the <Button> component.
SidebarOpen
The SidebarOpen is used to open the sidebar. It can be triggered by keyboard shortcut.
It extends the <Button> component.
SidebarMenuItem
A SidebarMenuItem extends the HTML <div> element. We list the extended properties only.
| Prop | Type | Default | Description |
|---|---|---|---|
label* | string | - | The title of the item. |
hint* | string | - | The tooltip of the item. |
icon* | LucideIcon | - | The displayed icon of the item. |
shortcut | string | - | The keyboard shortcut of the item. |
type SidebarConfig
The configuration object of the sidebar.
| Prop | Type | Default | Description |
|---|---|---|---|
defaultWidth* | string | 248px | Default width of the sidebar. |
defaultModileWidth* | string | 248px | Default width of the sidebar on mobile. |
minWidth* | string | 248px | Minimum draggable width of the sidebar. |
maxWidth* | string | 400px | Maximum draggable width of the sidebar. |
shortcut* | string | \ | Keyboard shortcut ⌘ + <shortcut> to toggle the sidebar. |
cookieName* | { state: string, width: string } | { state: "sidebar:state", width: "sidebar:width" } | Cookie names for sidebar state and sidebar width. |
cookieMaxAge* | number | 7d | Cookie's maximum lifetime (in seconds). |