Navigation

Sidebar

The navigation column of an app layout, on the start side of the page. On large screens it is always there; with stashable, below the lg breakpoint it hides off-screen and slides in as a drawer over a dimmed page, opened by a tk:sidebar.toggle button.

Page content beside the sidebar.
Blade

On large screens, a 16rem gray column on the left with the brand and the menu, staying in view while the page scrolls. On small screens the column is hidden and the header shows a menu button; tapping it slides the sidebar in over a dark backdrop and moves the focus into it. The close button, the backdrop, or Escape slide it out and return the focus to the menu button.

Two sidebars #

Toggles and sidebars are paired by name, so a page can have more than one drawer. Without a name, they pair with the unnamed sidebar.

Blade

Collapsing to icons #

On large screens a button with a double chevron narrows the sidebar to a 4rem column with the brand logo and the nav icons; each nav item then shows its name as a tooltip on the right. Clicking it again brings the labels back. The choice is kept in the browser for the next visits. Content of your own hides with the in-data-collapsed: variant (in-data-collapsed:hidden). Below lg the sidebar always shows its labels.

From your own code #

tallkit:sidebar-toggle and tallkit:sidebar-close events dispatched with the sidebar's name open or close a stashable sidebar. Each change, and the start of a stashable sidebar, dispatches tallkit:sidebar-state on window with { name, opened }. A tallkit:sidebar-collapse event on window with the sidebar's name collapses or expands a collapsible sidebar, as tk:sidebar.collapse does; each change, and its start, dispatches tallkit:sidebar-collapsed on window with { name, collapsed }.

Blade

Kept across pages #

With wire:navigate links, the sidebar stays on screen while the page changes: the menu keeps its scroll, the nav's indicator slides to the new page's link, and on small screens the drawer closes. On the first load the current page's link is scrolled into view. variant="ghost" leaves the column without background or border, as in a docs site, and gives the drawer a background.

Blade

Closing and following the state #

tallkit:sidebar-close closes the drawer, and tallkit:sidebar-state on window tells the page whether it is open (below lg, where the sidebar is a drawer).

Help

Need a hand with your orders? Write to [email protected].

Drawer opened:
Blade

Customization #

Classes on the tag replace the default width and background, and dark switches what is inside to the dark styles; backdrop: reaches the backdrop behind the drawer.

Blade

Reference

tk:sidebar
├── tk:sidebar.toggle (close button, optional)
└── content

tk:sidebar.toggle (open button, in the header)
Prop Type Default Description
name string null Pairs the sidebar with toggles of the same name.
sticky bool false Keeps the sidebar in view while the page scrolls, scrolling inside it when its content is taller than the viewport.
stashable bool false Below lg, hides the sidebar and opens it as a drawer.
collapsible bool false From lg, lets a tk:sidebar.collapse button narrow the sidebar to its icons (4rem), remembered in the browser.
persist bool | string false With Livewire, keeps the sidebar across wire:navigate page changes, with the scroll of the sidebar and of what scrolls inside it. A string is the persist key; by default it is sidebar- followed by the name (sidebar-main without one), so give each persisted sidebar of a page its own name.
scrollToCurrent bool true Scrolls the current page's link (data-current or aria-current="page") to the middle when it is out of view, on page load and when the drawer opens. It scrolls the sidebar, or the nav inside it when that is what scrolls, never the page.
variant string panel ghost removes the background and the border, and keeps a background only on the drawer.
ariaLabel string null Names the sidebar as a region landmark, translated.

Slots

Slot Description
default The sidebar content.

Prefixes

Prefix Goes to
backdrop: The dark backdrop behind the drawer.
Prop Type Default Description
name string null The sidebar it collapses and expands.

A tk:button with a double chevron, "Collapse sidebar" or "Expand sidebar" as its tooltip and name, and aria-expanded; hidden below lg. Takes the element props.

Prop Type Default Description
name string null The sidebar it opens and closes.

A tk:button with a menu icon and a "Toggle sidebar" tooltip; takes the element props (icon, label...) and the button props (variant...).

Slots

Slot Description
default The button content, in place of label.

Events

Tag Event Detail When
window tallkit:sidebar-state { name, opened } A stashable sidebar started, opened or closed.
window tallkit:sidebar-collapsed { name, collapsed } A collapsible sidebar started, collapsed or expanded.
tk:sidebar opened, closed The drawer opened or closed. Dispatched on the sidebar; do not bubble.

Customization

Classes and attributes on tk:sidebar go to the column. The backdrop takes a prefix (listed in the Reference above).

blade

The default width (w-64), padding, gap, background and border give way to classes passed on the tag.

Accessibility

The toggle has aria-controls pointing to the sidebar and an aria-expanded that follows it. While the drawer is closed on a small screen the sidebar is inert, so its links are out of the tab order. Opening it moves the focus to its first focusable element; closing it returns the focus to where it was.

Key Action
Escape Closes the drawer.
Tab / Shift+Tab While the drawer is open on a small screen, keeps the focus inside it, wrapping from the last element to the first and back.

Behavior notes

  • The sidebar takes the sidebar area of the grid that tk:main builds on its parent; placed right before a tk:header, it runs the full height of the page beside it. In any other parent it is a plain column.
  • persist wraps the backdrop and the sidebar in an x-persist element (data-tallkit-sidebar-persist) with display: contents, so the sidebar is still a cell of the layout grid. It is not x-persist on the sidebar itself because Livewire destroys the Alpine state of the persisted element, keeping only its children's. A stashable sidebar closes when wire:navigate starts, persisted or not.
  • A tk:nav inside a persisted sidebar drops its own @persist and travels with the sidebar: Livewire cannot put back a persisted element nested in another.
  • The sidebar has wire:ignore.self: a Livewire update keeps the drawer open or closed.
  • Until the script starts, a stashable sidebar stays hidden on small screens, so it does not flash open on load.