Animated Sidebar
Icon rail that expands on hover or focus and turns into a drawer on narrow screens.
- 2.9 KB gzipped
- Zero dependencies
- Reduced-motion safe
- Base UI & Radix compatible
Installation
pnpm dlx shadcn@latest add https://velora.colorlib.com/r/animated-sidebar.jsonAdds components/velora/animated-sidebar.tsx.
Examples
Dashboard shell
A pinned-capable rail beside a dashboard with stats, a chart and recent orders.
Narrow container
Below a 42rem container width the rail becomes a top bar with a drawer.
Props
Sidebar
| Prop | Type | Default |
|---|---|---|
pinnedControlled pinned-open state of the desktop rail | boolean | — |
defaultPinnedInitial pinned state when uncontrolled | boolean | false |
onPinnedChangeCalled when the pin toggle is pressed | (pinned: boolean) => void | — |
Also accepts every <div> attribute, forwarded to the root element.
SidebarBody
| Prop | Type | Default |
|---|---|---|
logoIcon-sized mark, always visible | React.ReactNode | — |
titleProduct name next to the logo; fades in with the labels | React.ReactNode | — |
footerLinks pinned to the bottom (e.g. settings or the account) | React.ReactNode | — |
labelAccessible name of the navigation landmark | string | "Main" |
pinnableShow the "Keep expanded" toggle at the bottom of the rail | boolean | true |
classNameClasses for the navigation panel (rail and drawer) | string | — |
children*SidebarLink elements | React.ReactNode | — |
SidebarLink
| Prop | Type | Default |
|---|---|---|
icon*Icon shown in both collapsed and expanded states | React.ReactNode | — |
label*Link text; stays the accessible name while the rail is collapsed | string | — |
activeMarks the current page (sets aria-current="page") | boolean | false |
Also accepts every <a> attribute, forwarded to the root element.
Accessibility
- Reduced motion
- The rail snaps between its collapsed and expanded widths, labels appear without fading and the drawer opens without sliding.
- Keyboard
- Links are native anchors; tabbing into the rail expands it. In the narrow layout the menu button opens a modal drawer that keeps Tab inside, closes on Escape or a backdrop click, and returns focus to the button.
- Screen readers
- A nav landmark (label prop) of links with aria-current on the active page; collapsed labels are only faded, so every link keeps its name, and the menu button reports aria-expanded.