Ballmac UI home

Sidebar

An app sidebar with icon-rail collapse, floating and inset variants, grouped menus with badges and sub-items, a mobile sheet, tooltips when collapsed and a Cmd/Ctrl+B shortcut.

Home

Collapse with the button or press ⌘B (Ctrl+B).

Installation

$ pnpm dlx shadcn@latest add @ballmac/sidebar

Usage

import { Sidebar, SidebarProvider, SidebarTrigger, SidebarInset, SidebarHeader, SidebarFooter, SidebarContent, SidebarSeparator, SidebarGroup, SidebarGroupLabel, SidebarGroupContent, SidebarMenu, SidebarMenuItem, SidebarMenuButton, SidebarMenuBadge, SidebarMenuSub, SidebarMenuSubItem, SidebarMenuSubButton, useSidebar } from "@/components/ballmac/sidebar"

The full example is in the Code tab above.

Examples

Icon rail, floating

Hover or focus an icon to see its name.

API reference

<SidebarProvider>

PropTypeDefault
defaultOpen

Initial open state when uncontrolled.

booleantrue
open

Controlled open state (desktop).

boolean—
onOpenChange

Called when the desktop sidebar opens or closes, for example to save the choice in a cookie.

(open: boolean) => void—
shortcut

Key that toggles the sidebar together with ⌘ (Ctrl on Windows and Linux). `false` turns the shortcut off.

string | false"b"

<Sidebar>

PropTypeDefault
side

Which edge the sidebar sits on. `start` (the default) and `end` follow the reading direction; `left` and `right` are fixed.

"start" | "end" | "left" | "right""start"
variant

`sidebar` is flush, `floating` is a rounded card with a gap, `inset` pairs with `SidebarInset`.

"sidebar" | "floating" | "inset""sidebar"
collapsible

`icon` collapses to an icon rail, `offcanvas` slides away, `none` is always open.

"offcanvas" | "icon" | "none""icon"
label

Accessible name of the navigation landmark (and of the mobile sheet).

string—

<SidebarMenuButton>

PropTypeDefault
href

Link target. When set the button renders as an `<a>`; add `aria-current="page"` via `isActive`.

string—
asChild

Render the child (a router link) with button styles and behavior.

booleanfalse
isActive

Highlight as the current page (sets `aria-current="page"` on links).

booleanfalse
tooltip

Tooltip text shown only while the sidebar is collapsed to icons. Defaults to the button's `aria-label`.

string—
size"default" | "sm" | "lg""default"

<SidebarMenuSubButton>

PropTypeDefault
isActivebooleanfalse

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Cmd/Ctrl+BToggles the sidebar
TabMoves through links; the current page has aria-current
MobileOpens as a named dialog sheet; Escape closes

Use with AI

SidebarProvider wraps Sidebar and SidebarInset. Menu entries use SidebarMenuButton with href and isActive. SidebarTrigger toggles it. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Sidebar (@ballmac/sidebar) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Application navigation with many sections
  • Dashboards and admin tools

Not for

  • Marketing site headers; use navigation-menu
  • Two or three links; use tabs

Registry JSON: https://ui.ballmac.com/r/sidebar.json

Credits

Based on shadcn/ui Sidebar, adapted by Ballmac. Free to use in personal and commercial projects.