Sidebar

Composable navigation sidebar for app shells with collapsible sections, search and filter, tree views with hover actions, and a mobile menu

import {
SidebarProvider,
SidebarLayout,
Sidebar,
SidebarHeader,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupLabel,
SidebarMenu,
SidebarMenuItem,
SidebarMenuButton,
SidebarInset,
SidebarTrigger,
} from "@plexui/vue/components/Sidebar";

Examples

The examples use local ResponsiveSidebarProvider, ResponsiveSidebar and SidebarDemoPage helpers from Responsive composition. They keep the desktop rail and use the existing SidebarMobile drawer with a Page toolbar on phones. The mobile presentation is a navigation adaptation, not an iPad sidebar squeezed into a phone. On a phone the examples leave out the controls that only change the desktop sidebar, open, collapsible and labelSize: the drawer is the same with each of them.

The examples read their navigation data (navGroups, docsSections, iconSections, consoleSections, ...) from the setup scope, where a real app defines it in <script setup> with icon components imported from @plexui/vue/components/Icon. The default slot of SidebarProvider receives the sidebar state and controls (v-slot="sidebar"), the same object useSidebar() returns.

App Shell

App

Basic

collapsible
labelSize

Collapsible Sections

Search and Filter

expand

Tree with Hover Actions

action

Mobile Menu

Search Input

Responsive composition

These application-local helpers choose the layout from the viewport. Desktop collapse remains independent of the mobile drawer. On a phone the drawer is a grouped page with a large title and a close button, as the sidebar of an iPhone app is: each menu is a card of 52px rows, a group label heads its section, a row that leads to a page ends with a disclosure chevron, and an item with a submenu keeps its own chevron, which turns down as its items open under it. The drawer itself is a modal dialog while it is open: focus moves into it and stays there, the page behind it is inert, Escape inside it closes it, and focus returns to the menu button. A swipe in from the edge it slides from opens it, and a swipe back closes it. Keep navigation selection handlers on the row buttons; popup and disclosure buttons do not close the drawer.

Save the helpers in responsive-sidebar.ts and the styles in responsive-sidebar.module.css:

import { defineComponent, h, type PropType } from 'vue';
import { NavigationButton } from '@plexui/vue/components/Button';
import { Page, PageBar, PageContent, PageHeader, PageLeading, PageTitle } from '@plexui/vue/components/Page';
import { Sidebar, SidebarInset, SidebarMobile, SidebarMobileMenuButton, SidebarProvider, useSidebar as sidebarContext, type SidebarCollapsible, type SidebarProviderVariant } from '@plexui/vue/components/Sidebar';
import { Toolbar, ToolbarTitle, ToolbarTrailing } from '@plexui/vue/components/Toolbar';
import { useBreakpoint as breakpoint } from '@plexui/vue/composables/useBreakpoints';
import s from './responsive-sidebar.module.css';
/** Leaf navigation closes the drawer; disclosure and popup buttons keep it open. */
export function isSidebarNavigationSelection(target: EventTarget | null) {
  if (!(target instanceof Element)) return false;
  const button = target.closest('[data-active]');
  return Boolean(button && !button.hasAttribute('aria-haspopup') &&
    !button.hasAttribute('aria-expanded') && !button.closest('li')?.querySelector(':scope > ul'));
}

export const ResponsiveSidebarProvider = defineComponent({
  name: 'ResponsiveSidebarProvider',
  inheritAttrs: false,
  props: {
    open: { type: Boolean, default: undefined },
    collapsible: { type: String as PropType<SidebarCollapsible>, default: 'offcanvas' },
    variant: { type: String as PropType<SidebarProviderVariant>, default: 'sidebar' },
  },
  setup(props, { attrs, slots }) {
    const wide = breakpoint('md');
    return () => h(SidebarProvider, {
      ...attrs,
      ...props,
      class: [s.Frame, attrs.class],
      open: wide.value ? props.open : true,
      variant: wide.value ? props.variant : 'sidebar',
    }, slots);
  },
});

export const ResponsiveSidebar = defineComponent({
  name: 'ResponsiveSidebar',
  inheritAttrs: false,
  setup(_, { attrs, slots }) {
    const sidebar = sidebarContext();
    return () => sidebar.isMobile
      ? h(SidebarMobile, { contained: true, class: s.Drawer, 'aria-label': 'Navigation' }, () =>
        h(Page, { surface: 'grouped' }, () => [
          h(Toolbar, { titleStyle: 'large' }, () => [
            h(ToolbarTitle, null, () => 'Navigation'),
            h(ToolbarTrailing, null, () => h(NavigationButton, { action: 'close', 'aria-label': 'Close menu', onClick: () => sidebar.setOpenMobile(false) })),
          ]),
          h(PageContent, { class: s.NavigationContent, onClick: (event: MouseEvent) => {
            if (!event.defaultPrevented && isSidebarNavigationSelection(event.target)) sidebar.setOpenMobile(false);
          } }, slots),
        ]))
      : h(Sidebar, attrs, slots);
  },
});

export const SidebarDemoPage = defineComponent({
  name: 'SidebarDemoPage',
  props: { title: { type: String, required: true } },
  setup(props, { slots }) {
    const sidebar = sidebarContext();
    return () => h(SidebarInset, { class: s.Inset }, () => sidebar.isMobile
      ? h(Page, null, () => [
        h(PageHeader, null, () => h(PageBar, null, () => [
          h(PageLeading, null, () => h(SidebarMobileMenuButton)),
          h(PageTitle, null, () => props.title),
        ])),
        h(PageContent, null, slots),
      ])
      : h('div', { class: 'p-6' }, [h('h1', { class: 'text-2xl font-semibold mb-4' }, props.title), slots.default?.()]));
  },
});
.Frame {
  position: relative;
}

.Drawer {
  padding: 0;
}

.NavigationContent {
  --page-content-padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
}

@media (max-width: 767px) {
  .Frame {
    --sidebar-mobile-button-size: 44px;
    height: 100dvh;
    overflow: hidden;
  }

  .Frame > :global([class*="SidebarLayout"]) {
    height: 100%;
  }

  .Inset {
    margin: 0;
    overflow: hidden;
    border-radius: 0;
    box-shadow: none;
  }
}

API

Structure

A Sidebar is composed of the following parts:

  • SidebarProvider: Handles collapsible state and provides context to all child components.
  • SidebarLayout: Wrapper for sidebar and main content.
  • Sidebar: The sidebar container.
  • SidebarHeader / SidebarFooter: Sticky at the top and bottom of the sidebar.
  • SidebarContent: Scrollable content area.
  • SidebarGroup: Section within the content, with optional label.
  • SidebarMenu / SidebarMenuItem / SidebarMenuButton: Navigation menu items.
  • SidebarMenuSub / SidebarMenuSubButton: Nested submenu items.
  • SidebarInset: Main content area next to the sidebar.
  • SidebarTrigger: Toggle button for collapsing the sidebar.

Use Cmd+B (Mac) or Ctrl+B (Windows/Linux) to toggle the sidebar with keyboard.

SidebarProvider

Handles sidebar state and provides context to all child components. Wrap your application layout in this provider.

PropTypeDefaultDescription
collapsible"offcanvas" | "icon" | "none""offcanvas"Collapse behavior: offcanvas (drawer on mobile, full collapse on desktop), icon (icon rail), or none
variant"sidebar" | "app""sidebar"Look of the whole shell. "app" is the sidebar of a product: 260px, pill rows on a grey ground, a page with no inset, and on a phone a menu under the page
default-openbooleantrueInitial open state (uncontrolled)
openboolean—Controlled open state. Bind with v-model:open
@update:open(open: boolean) => void—Emitted when the open state changes; powers v-model:open. Without open the provider keeps its own state and still emits
default-open-mobilebooleanfalseInitial open state of the phone drawer (uncontrolled)
open-mobileboolean—Controlled open state of the phone drawer. Bind with v-model:open-mobile
@update:open-mobile(open: boolean) => void—Emitted when the phone drawer opens or closes: its menu button, its backdrop, Escape or a swipe; powers v-model:open-mobile. Without open-mobile the provider keeps its own state and still emits
classstring—Class of the provider's wrapper
styleStyleValue—Style of the provider's wrapper, e.g. --sidebar-width
default slot{ state, open, setOpen, openMobile, setOpenMobile, isMobile, collapsible, toggleSidebar }—Receives the sidebar context, the object useSidebar() returns

The main sidebar container. Renders as an <aside> element.

PropTypeDefaultDescription
variant"sidebar" | "docs""sidebar"Visual variant
side"left" | "right""left"Which side the sidebar is on

SidebarGroup

A section within SidebarContent.

PropTypeDefaultDescription
default-openbooleantrueWhether the group is open initially. A closed group hides its SidebarGroupContent
openboolean—Controlled open state, also exposed as data-state. The group has no toggle of its own: change open from your own control

SidebarGroupLabel

Renders a section label within a SidebarGroup. Supports two size variants.

PropTypeDefaultDescription
size"sm" | "lg""lg"sm: compact, tertiary. lg: larger, primary, more spacing
as-childbooleanfalseRender the single child element as the label

SidebarMenuItem

PropTypeDefaultDescription
expandedboolean—Marks the item expanded, which turns its SidebarMenuChevron. Pair it with open on its SidebarMenuSub

SidebarMenuButton

Renders a menu item button. Use is-active to highlight the current page.

PropTypeDefaultDescription
is-activebooleanfalseHighlight the current page (aria-current="page")
tooltipstring—Label shown on hover when collapsed (icon mode). Hidden on mobile. The tooltip slot takes rich content
as-childbooleanfalseRender the single child element (e.g. a RouterLink) as the button. The button attributes go on the child and its content is wrapped like the button's

SidebarMenuBadge

Trailing content of a row: a Badge, or plain text such as a count, which reads as small secondary figures. A Badge sits as far from the row's edge as from its top and bottom, and its digits end where plain counts and the chevron end. When the sidebar collapses to icons, a Badge becomes a dot of its color at the top right of the row's icon, clear of the glyph; plain text fades with the label.

SidebarMenuSub

Renders a collapsible submenu container for nested navigation.

PropTypeDefaultDescription
openbooleantrueWhether submenu is expanded. A closed submenu is inert, so its links and buttons leave the tab order and the accessibility tree
has-iconsbooleanfalseAlign child items with parent text that has icons

SidebarMenuSubButton

PropTypeDefaultDescription
is-activebooleanfalseHighlight the current page (aria-current="page")
indent0 | 1 | 2 | 30Nesting level; each level adds 12px of left margin
as-childbooleanfalseRender the single child element (e.g. a RouterLink) as the button

SidebarMobile

The phone drawer, with its backdrop. While it is open it is a modal dialog (role="dialog", aria-modal, labelled "Menu" unless you pass aria-label): focus moves to its first control and stays inside, SidebarInset is inert, Escape inside it closes it (a @keydown handler that calls event.preventDefault(), or a menu over it that takes its own Escape, keeps it open), and focus goes back to the control that opened it, or to the SidebarMobileMenuButton when that control can no longer take focus (it sat in another drawer that has closed, or it is gone). Closed, it is inert. A swipe in from the edge it slides from opens it, and a swipe back closes it; the drawer follows the finger and finishes by speed or distance.

PropTypeDefaultDescription
containedbooleanfalsePositions the drawer and backdrop absolute inside a frame instead of fixed to the window
disclosurebooleantrueRows that lead to another page end with a disclosure chevron, as in an iOS list. false leaves it out

SidebarTrigger

Collapse button. Renders nothing when collapsible="none". The default icon is Sidebar in both states, and a tooltip can say what a press does; the default slot replaces it. A @click listener runs before the toggle; call event.preventDefault() in it to cancel the toggle. SidebarMobileMenuButton, the mobile menu button (the PlexUI SidebarMenuMobile icon, which turns into X while the menu is open), handles @click the same way.

SidebarInput

A search field: Input with a search icon as its start adornment. Every attribute, listener and slot goes to the Input (v-model:value, @clear, ...).

SidebarCard

Renders a promotional card in the sidebar footer for CTAs, upgrades, or announcements.

PropTypeDefaultDescription
variant"default" | "elevated""default"Visual variant
dismissiblebooleanfalseShows dismiss button
@dismiss(event: MouseEvent) => void—Emitted when the dismiss button is clicked

useSidebar

Composable to access sidebar state and controls from the setup() of any component within SidebarProvider. It returns a reactive object: read its fields (sidebar.state) rather than destructuring them outside a render.

  • state: Current state: "expanded" or "collapsed"
  • open / setOpen: Desktop sidebar open state
  • openMobile / setOpenMobile: Mobile menu open state
  • isMobile: Whether the viewport is mobile
  • collapsible: Current collapsible mode
  • toggleSidebar: Toggle function for both desktop and mobile

Styling

Sidebar reads these component tokens. Override them at any scope to restyle it. SidebarProvider sets the three width tokens on its own element, so change those through its style (or on an element inside it):

  • --sidebar-accent: accent (default light-dark(var(--alpha-08), var(--alpha-12)))
  • --sidebar-background: background (default none)
  • --sidebar-border: border (default var(--color-border))
  • --sidebar-collapse-duration: collapse duration (default 0.3s)
  • --sidebar-footer-shadow: footer shadow
  • --sidebar-foreground: foreground (default var(--color-text))
  • --sidebar-group-label-color: group label color (default var(--color-text-tertiary))
  • --sidebar-gutter: gutter (default 12px)
  • --sidebar-gutter-sm: gutter sm (default var(--control-gutter-2xs))
  • --sidebar-header-height: header height (default var(--control-size-3xl))
  • --sidebar-icon-margin: icon margin (default 0 2px 0 4px)
  • --sidebar-icon-size: icon size (default 20px)
  • --sidebar-icon-wrapper-size: icon wrapper size (default 32px)
  • --sidebar-inset-shadow: inset shadow (default none)
  • --sidebar-menu-badge-dot-size: size of the dot a Badge becomes above the icon in the collapsed rail (default 6px)
  • --sidebar-menu-item-font-size: menu item font size (default 14px)
  • --sidebar-menu-item-height: menu item height (default 38px)
  • --sidebar-menu-item-height-desktop: menu item height desktop (default 32px)
  • --sidebar-menu-item-line-height: menu item line height (default 20px)
  • --sidebar-menu-item-margin: menu item margin (default 0 0 2px)
  • --sidebar-menu-item-margin-desktop: menu item margin desktop (default 0 0 2px)
  • --sidebar-menu-item-padding: menu item padding (default 0)
  • --sidebar-menu-item-radius: menu item radius (default 8px)
  • --sidebar-menu-item-trailing-padding: where counts and the chevron end, from the row's right edge (default 12px)
  • --sidebar-menu-text: menu text (default light-dark(var(--gray-750), var(--gray-850)))
  • --sidebar-menu-text-active: menu text active (default var(--gray-900))
  • --sidebar-mobile-backdrop-color: mobile backdrop color (default light-dark(rgb(0 0 0 / 15%), rgb(0 0 0 / 35%)))
  • --sidebar-mobile-button-radius: mobile button radius (default 8px)
  • --sidebar-mobile-button-size: mobile button size (default 32px)
  • --sidebar-mobile-enter-delay: mobile enter delay (default 0.33s)
  • --sidebar-mobile-enter-opacity-duration: mobile enter opacity duration (default 0.8s)
  • --sidebar-mobile-enter-transform-duration: mobile enter transform duration (default 0.7s)
  • --sidebar-mobile-exit-duration: mobile exit duration (default 0.3s)
  • --sidebar-mobile-gutter: mobile gutter (default 12px)
  • --sidebar-mobile-header-height: mobile header height (default 48px)
  • --sidebar-mobile-icon-size: mobile menu icon size (default 24px)
  • --sidebar-mobile-icon-color: mobile menu icon color (default var(--gray-900))
  • --sidebar-mobile-icon-transition-duration: duration of the menu icon turning into the close icon (default 0.2s)
  • --sidebar-mobile-z-index: mobile z index (default 301)
  • --sidebar-transition-duration: transition duration (default 0.3s)
  • --sidebar-width: width (SidebarProvider sets 240px)
  • --sidebar-width-icon: width icon (SidebarProvider sets 64px)
  • --sidebar-width-mobile: width mobile (SidebarProvider sets 288px)
  • --skeleton-background: background (default light-dark(var(--alpha-08), var(--alpha-12)))
  • --skeleton-radius: radius (default var(--radius-md))