Sidebar
NewA composable, themeable, and collapsible sidebar for application layouts.
Preview
Press Ctrl + B (Cmd + B on macOS) to toggle the sidebar, or click the rail on its edge.
Installation
npx sigma-ui@latest add sidebarUsage
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarInset,
SidebarProvider,
SidebarTrigger,
} from '@/components/ui/sidebar';
</script>
<template>
<SidebarProvider>
<Sidebar>
<SidebarHeader />
<SidebarContent />
<SidebarFooter />
</Sidebar>
<SidebarInset>
<SidebarTrigger />
<RouterView />
</SidebarInset>
</SidebarProvider>
</template>Structure
A sidebar is made of these parts:
SidebarProvider- holds the open state, persists it in a cookie, and handles the keyboard shortcut.Sidebar- the sidebar container. Renders a sheet on mobile.SidebarHeaderandSidebarFooter- sticky top and bottom sections.SidebarContent- the scrollable body.SidebarGroup- a section insideSidebarContent, withSidebarGroupLabel,SidebarGroupAction, andSidebarGroupContent.SidebarMenu- a list ofSidebarMenuItemcomponents, each with aSidebarMenuButtonand optionalSidebarMenuAction,SidebarMenuBadge, andSidebarMenuSub.SidebarTriggerandSidebarRail- controls that toggle the sidebar.SidebarInset- the main content area next to the sidebar.
Notes
useSidebar()returnsstate,open,setOpen,isMobile,openMobile,setOpenMobile, andtoggleSidebar. Call it inside any component rendered withinSidebarProvider.The desktop open state is saved in the
sidebar_statecookie. Change the name with thecookie-nameprop, or pass an empty string to disable it. In Nuxt, read the cookie withuseCookie('sidebar_state')and pass it todefault-opento avoid a layout shift on page load.Below the
mdbreakpoint (48rem, 768px at the default font size) the sidebar renders as a sheet.collapsible="icon"shrinks it to icons only on desktop; passtooltiptoSidebarMenuButtonto show labels on hover while collapsed.Override the width with the
--sidebar-widthand--sidebar-width-iconCSS variables onSidebarProvider.
Examples
Floating
Use variant="floating" to detach the sidebar from the edge of the screen with a border and shadow.
Inset
Use variant="inset" together with SidebarInset to place the main content in a raised card.
Menu actions and badges
SidebarMenuAction adds a secondary action to a menu item, SidebarMenuBadge shows a counter, and SidebarMenuSkeleton is a loading placeholder.
Controlled
Use v-model:open on SidebarProvider to control the sidebar from your own state.
API Reference
Sidebar
Props
| Prop | Type | Default |
|---|---|---|
sideSide of the screen the sidebar is attached to. | "right" | "left" | "left" |
variantVisual style. | "inset" | "sidebar" | "floating" | "sidebar" |
collapsibleCollapse behavior on desktop. | "icon" | "offcanvas" | "none" | "offcanvas" |
Slots
| Slot | Scope |
|---|---|
defaultSidebar sections such as | - |
SidebarContent
Slots
| Slot | Scope |
|---|---|
defaultScrollable sidebar body, usually one or more | - |
SidebarFooter
Slots
| Slot | Scope |
|---|---|
defaultFooter content, such as a user menu. | - |
SidebarGroup
Slots
| Slot | Scope |
|---|---|
defaultGroup parts: | - |
SidebarGroupAction
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "button" |
Slots
| Slot | Scope |
|---|---|
defaultAction icon. Add a visually hidden label for screen readers. | - |
SidebarGroupContent
Slots
| Slot | Scope |
|---|---|
defaultGroup body, usually a | - |
SidebarGroupLabel
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultLabel text, optionally with an icon. | - |
SidebarHeader
Slots
| Slot | Scope |
|---|---|
defaultHeader content, such as a team switcher or a search input. | - |
SidebarInput
Props
| Prop | Type | Default |
|---|---|---|
modelValueCurrent value of the input; use with | string | number | - |
Events
| Event | Payload |
|---|---|
update:modelValueEmitted when the user changes the value. | unknown[] |
SidebarInset
Slots
| Slot | Scope |
|---|---|
defaultMain page content rendered next to the sidebar. | - |
SidebarMenu
Slots
| Slot | Scope |
|---|---|
defaultList of | - |
SidebarMenuAction
Props
| Prop | Type | Default |
|---|---|---|
showOnHoverShows the action only while the menu item is hovered or focused. | boolean | false |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "button" |
Slots
| Slot | Scope |
|---|---|
defaultAction icon. Add a visually hidden label for screen readers. | - |
SidebarMenuBadge
Slots
| Slot | Scope |
|---|---|
defaultBadge content, such as a counter. | - |
SidebarMenuButton
Props
| Prop | Type | Default |
|---|---|---|
tooltipTooltip shown when the sidebar is collapsed to icons. Accepts a string or a component. | string | Component | - |
variantVisual style of the button. | "default" | "outline" | null | "default" |
sizeHeight and text size of the button. | "default" | "sm" | "lg" | null | "default" |
isActiveMarks the button as the current page or section. | boolean | false |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "button" |
Slots
| Slot | Scope |
|---|---|
defaultButton content, usually an icon followed by a | - |
SidebarMenuItem
Slots
| Slot | Scope |
|---|---|
defaultA | - |
SidebarMenuSkeleton
Props
| Prop | Type | Default |
|---|---|---|
showIconRenders an icon placeholder before the text placeholder. | boolean | false |
SidebarMenuSub
Slots
| Slot | Scope |
|---|---|
defaultList of | - |
SidebarMenuSubButton
Props
| Prop | Type | Default |
|---|---|---|
sizeText size of the button. | "sm" | "md" | "md" |
isActiveMarks the button as the current page. | boolean | false |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "a" |
Slots
| Slot | Scope |
|---|---|
defaultButton content, usually a | - |
SidebarMenuSubItem
Slots
| Slot | Scope |
|---|---|
defaultA | - |
SidebarProvider
Props
| Prop | Type | Default |
|---|---|---|
defaultOpenInitial open state on desktop when | boolean | true |
openControlled open state on desktop. Use with | boolean | - |
cookieNameName of the cookie that persists the desktop open state between visits. Set to an empty string to disable persistence. | string | SIDEBAR_COOKIE_NAME |
keyboardShortcutKey that toggles the sidebar together with | string | SIDEBAR_KEYBOARD_SHORTCUT |
Events
| Event | Payload |
|---|---|
update:openEmitted when the desktop open state changes. | [open: boolean] |
Slots
| Slot | Scope |
|---|---|
defaultThe sidebar and the main content of the layout. | { open: boolean; state: SidebarState; isMobile: boolean; } |
SidebarRail
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SidebarSeparator
This component has no props, events, or slots.
SidebarTrigger
Slots
| Slot | Scope |
|---|---|
defaultCustom trigger icon. Defaults to a panel icon. | - |
Accessibility
The sidebar is built from native buttons and links, so its menu items are reachable with the keyboard. On mobile it renders as a sheet that follows the Dialog WAI-ARIA design pattern. SidebarTrigger has a screen reader label, and SidebarRail is skipped in the tab order because the trigger and the shortcut cover it.
Keyboard Support
| Button | Action |
|---|---|
ctrl+b | Toggles the sidebar. Uses cmd+b on macOS. |
| Key | Description |
|---|---|
| Ctrl + B | Toggles the sidebar. Use Cmd + B on macOS. Change the key with the keyboard-shortcut prop on SidebarProvider. |
| Tab | Moves focus to the next menu button, action, or link. |
| Enter | Activates the focused menu button or link. |
| Esc | On mobile, closes the sidebar sheet. |