Sidebar
An app's navigation column: a sticky rail beside the page from a breakpoint
up, a drawer below it, and one copy of the nav in the DOM either way. It
holds a header (the workspace), the nav items and a footer (the account),
and, when collapsible, folds to icons and remembers it in a cookie.
Anatomy
div[data-ds-sidebar][x-data=dsSidebar] root: the rail's box; fixed over the page as a drawer
│ style="--ds-sidebar-width; --ds-sidebar-rail-width"
│ data-ds-sidebar-collapsed (server: the starting state; then bound)
├── div[data-ds-sidebar-close] the drawer's backdrop (hidden as a rail)
└── div#id[data-ds-sidebar-panel] role=dialog aria-modal only while open as a drawer
├── div p#id-title (menuLabel) · button[data-ds-sidebar-close] "Close" drawer only
└── div.flex-col.gap-4.p-3
├── div header slot
├── nav[aria-label=label] default slot, scrolls on its own
├── div footer slot
└── div button[data-ds-sidebar-collapse][aria-pressed] collapsible, rail only, script only
There is no ds::app-shell: the page's own row (lg:flex), the header bar,
the skip link and main stay in the host's layout, which is the one file a
host edits anyway. The sidebar is the part with behaviour.
One element, three presentations
| Where | Classes (for drawerBelow="lg") | What it is |
|---|---|---|
lg and up | lg:sticky lg:top-0 lg:h-(--ds-sidebar-height,100dvh) lg:w-(--ds-sidebar-width) | A rail in the page's row, its own height, its own scroll |
below lg, scripting on | max-lg:[@media(scripting:enabled)]:fixed inset-0 z-50, the panel absolute start-0 -translate-x-full invisible | Off-canvas until data-ds-sidebar-open; then on screen, with a backdrop |
below lg, scripting off | none of those | A block above the page with every link: a menu button that cannot open would hide the navigation |
The breakpoint classes are written out per breakpoint (sm, md, lg,
xl, and a rail at every width with drawerBelow false) so a consumer's
Tailwind sees each. The script does not copy the breakpoint: it asks the CSS
(position: fixed on the root means a drawer), so a host that redefines
lg moves both.
Collapsed, data-ds-sidebar-collapsed narrows the root to
--ds-sidebar-rail-width (3.5rem: a 2rem item and 0.75rem each side). The
items inside are not told by CSS but by Alpine, through @aware.
What the children read
View/Components/Sidebar.php exposes dsSidebar (collapsible, the starting
collapsed, and the expression collapsed). nav-item, sub-nav,
team-switcher and user-menu @aware it, a key no other component has, so
inside a collapsible sidebar they take collapsedWhen / compactWhen and
their starting state from it, and anywhere else render exactly as before. A
prop set on the child wins.
Behaviour (dsSidebar, in the core)
| Exposed | Meaning |
|---|---|
collapsed | The rail is icons only. Never true while a drawer (a drawer has room). Read it; the toggle changes it. |
dsSidebarOpen | The drawer is open. Prefixed so it cannot shadow a host's open. |
- The menu button is the host's, in its header: any element with
aria-controlsnaming the panel's id. A delegated click on the document toggles the drawer and the script keeps every such button'saria-expanded. A link as the opener has its navigation prevented. - Closing: Escape (the modal layer's, top layer only), the Close button, the backdrop, following a link in the drawer, and growing past the breakpoint (a resize, read from the CSS).
- While open as a drawer the modal layer (partials/modal.php) applies: focus into the panel and back to the opener, the Tab trap, the scroll lock, the overlay stack. Tab is trapped only while open, so the rail beside a page never holds focus.
- The collapse toggle flips
collapsedand, withcookie, writes<cookie>=collapsed|expanded; path=/; max-age=31536000; samesite=lax. The server reads it in the class (collapsedorexpanded; anything else falls back to thecollapsedprop), so the next page's first paint is right.
Accessibility
- Landmark: one
nav, named bylabel("Primary" by default). The header and footer slots are outside it: a workspace switcher and an account menu are not navigation. Two navs on one page need two names. - Drawer:
role="dialog",aria-modal="true", named by the visiblemenuLabelthrougharia-labelledby, only while open; closed, the panel isvisibility: hidden, so nothing inside is reachable. - Collapse toggle: a toggle button,
aria-pressed(pressed = folded), named bycollapseLabel, its chevrons an icon-swap. - Collapsed items keep their names: nav-item's
titleand hidden label, the switchers' names moved into their buttons. - Skip link: the host's, first in the body, to
main; the sidebar comes after it in the source.
| Key | Where | What it does |
|---|---|---|
| Enter, Space | menu button | Opens the drawer, focus inside it |
| Tab, Shift+Tab | open drawer | Cycles within it |
| Escape | open drawer | Closes it, focus back on the menu button |
| Enter, Space | collapse toggle | Folds or unfolds the rail |
Motion
The drawer slides with the slide tokens (duration-slide-enter /
-leave), its backdrop fading with it, both motion-safe:; with reduced
motion it appears at once. The rail's width changes at once.
Do not
- Do not draw the nav twice for a phone drawer. The sidebar is the drawer.
- Do not put the menu button inside the sidebar. It opens the sidebar
from the page's header, by
aria-controls. - Do not write
collapsedfrom outside to fold the rail: the toggle keeps the cookie in step. Read it. - Do not leave out the
encryptCookiesexception when you name a cookie: Laravel discards a cookie it cannot decrypt, and the rail is drawn wide on every page. - Do not put a second
navlandmark named "Primary" on the page (a bottom nav): give it anotherlabel.
From the package repo: edit this page on GitHub.