Sidebar
A config-first app-shell navigation rail. One items array renders grouped links with icons and badges, animated collapsible submenus, and active-route highlighting — plus an optional-controlled collapsed icon-only mode with header and footer slots.
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece sidebar
This is the rail only. Compose off-canvas mobile behavior at the app level — render the Sidebar inside a Sheet on small screens and inline it from md: up. The rail expects a bounded-height parent.
Usage
import Sidebar from '@/components/ui/Sidebar.pzl';
<Sidebar items={ items } activePath="/reports/overview" label="Main"></Sidebar>Collapsed rail
Header and footer slots
Accessibility
- The rail is a real
<nav>with an accessible label prop (default Main), and links live in a semantic<ul>. - The link matching
activePath— top-level or submenu child — is markedaria-current="page"alongside the visual tint, so it is announced as the current page. - Each submenu is a disclosure: the button carries
aria-expandedandaria-controls; the closed region isinert+ aria-hidden, so its links leave the tab order and the accessibility tree. - In the collapsed rail, labels stay mounted and fade to
opacity-0rather than becoming screen-reader-only; each icon link or button keeps atitlefor its sighted tooltip while the mounted label remains its accessible name. - Group headings stay in the accessibility tree when collapsed: their animated grid track loses height, but the heading itself remains present.
- A collapsed parent trigger carries
aria-haspopupand swapsaria-controlsfrom the inline region to the flyout panel. The panel is labelled by the trigger, and Escape dismisses it and refocuses the button. - The collapse control is the rail's right edge itself: a full-height button with
aria-pressedand a state-aware label. It is keyboard-reachable, and focusing it reveals the same highlight and arrow that hovering does — no pointer required. - Every link and button shows a visible focus ring (unconditional outline color, revealed on
:focus-visible), and the width and submenu animations honorprefers-reduced-motion.