Skip to content

SidebarLayout ​

A responsive two-panel layout with a collapsible sidebar and main content area. On mobile, the sidebar becomes an overlay. A second sidebar can sit on the right.

When the sidebar is collapsed it is marked inert, so its contents (including the collapse button) are removed from the tab order and the accessibility tree while visually hidden. The expand button is likewise inert while the sidebar is open. This keeps keyboard and screen-reader focus on whichever control is actually visible.

On a phone the sidebar is never wider than the screen, and the main content it pushes aside is clipped rather than left to scroll the page sideways. If keyboard focus moves into that hidden main content, the sidebar collapses so the focused control is on screen.

Printing ​

The layout prints as a plain document: the sidebar, header bands and tabs bar are hidden, the main pane unrolls to its full height so the active content paginates, and the theme switches to the light color scheme (@media print in theme.css), so a dark-mode screen prints dark text on white. Inactive tab panels are the consumer's to hide (for example with inert and height: 0).

Demo ​

Open in full window ↗

Tabs Demo (Router Mode) ​

Open in full window ↗

Two Sidebars Demo ​

Open in full window ↗

Usage ​

vue
<SidebarLayout>
  <template #sidebar>
    <h2>Controls</h2>
    <NumberInput v-model="value" label="Parameter" slider live />
  </template>
  <h1>Main Content</h1>
  <p>Your charts and data go here.</p>
</SidebarLayout>

Slots ​

SlotDescription
sidebarContent rendered in the left sidebar panel
sidebar-header-startLeft side of the sidebar's header band, e.g. a pane title
sidebar-header-endRight side of the sidebar's header band, beside the collapse button
sidebar-rightContent of the right sidebar panel. The panel only exists when this slot is given
sidebar-right-header-startLeft side of the right sidebar's header band, after its collapse button
sidebar-right-header-endRight side of the right sidebar's header band
topbar-startLeft side of the main header: before the tabs, or alone without them
topbar-endRight side of the main header, beside the light/dark toggle (topbar still works as the old name)
defaultMain content area

Buttons, selects and text fields placed in the header slots take the header's control height (28px), so they line up with the collapse and light/dark toggles:

vue
<SidebarLayout :tabs="tabs">
  <template #sidebar-header-start>
    <h2>Parameters</h2>
  </template>
  <template #sidebar-header-end>
    <Button variant="neutral" @click="reset">Reset</Button>
  </template>
  <template #topbar-end>
    <Button variant="neutral" @click="exportCsv"><Icon icon="download" :size="16" /> Export</Button>
  </template>
  ...
</SidebarLayout>

Props ​

PropTypeDefaultDescription
hideTopbarbooleanfalseHides the topbar that contains the light/dark toggle
tabsTab[]undefinedArray of tab definitions to render in the main area
maxWidthstring | number1024pxMax width of the main content: a CSS length ("none" for full width) or pixels
v-model:tabstringundefinedThe active tab value (two-way binding)

Tab is the Tabs component's tab type.

Give the sidebar-right slot to add a second sidebar on the right of the main content, for example a summary or details panel beside the parameters on the left. It has a separate collapse button and header slots, and is styled like the left one.

vue
<SidebarLayout>
  <template #sidebar>
    <NumberInput v-model="population" label="Population" slider live />
  </template>
  <template #sidebar-right-header-start>
    <h2>Summary</h2>
  </template>
  <template #sidebar-right>
    <p>Estimated infections: {{ infections }}</p>
  </template>
  <h1>Main Content</h1>
</SidebarLayout>

The right sidebar is 320px wide; set the --sidebar-right-width theme token to change it (the left one reads --sidebar-width).

Both sidebars start open when the window is at least 1200px wide. On a narrower window the right one starts collapsed and only one sidebar is open at a time: expanding one collapses the other. The 1200px is fixed and sized for the default widths (400px, 320px and a 480px main pane), so it does not follow the width tokens. On a phone the right sidebar slides in over the main content from a button at the end of the main header.

With a right sidebar the two <aside> panels are labelled "Left sidebar" and "Right sidebar", and the right one's buttons are named "Collapse right sidebar" and "Expand right sidebar", so assistive technology can tell the two apart.

Tabs ​

When the tabs prop is provided, a Tabs strip renders in the header of the main content area. If the tabs do not fit beside the header's other controls, the tab list scrolls sideways. When the main area is narrower than 480px (a phone), the tabs move to their own row under the header controls, so the controls stay on screen. Tabs support two modes:

Local mode ​

Use v-model:tab to control which tab is active. Render content conditionally in the default slot.

vue
<script setup>
import { ref } from "vue";
const activeTab = ref("chart");
</script>

<SidebarLayout
  v-model:tab="activeTab"
  :tabs="[
    { value: 'chart', label: 'Chart' },
    { value: 'data', label: 'Data' },
  ]"
>
  <template #sidebar>
    <h2>Controls</h2>
  </template>
  <div v-if="activeTab === 'chart'">Chart content</div>
  <div v-if="activeTab === 'data'">Data table</div>
</SidebarLayout>

Router mode ​

When tabs include a to property and vue-router is installed, clicking a tab navigates to that route. The active tab is automatically determined from the current route.

vue
<SidebarLayout
  :tabs="[
    { value: 'chart', label: 'Chart', to: '/model/chart' },
    { value: 'data', label: 'Data', to: '/model/data' },
  ]"
>
  <template #sidebar>
    <h2>Controls</h2>
  </template>
  <RouterView />
</SidebarLayout>