On this page

Sidebar

Live examples of Sidebar, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz.

App navigation

Groups of links with icons; it collapses to icons and opens as a drawer on phones.

Integrations

Collapse the navigation with the button, the edge strip or Ctrl+B. In the rail, each label shows in a tooltip.

SidebarApp.vue
<script setup lang="ts">
import { ArrowLeftRight, Blocks, LayoutDashboard, ScrollText, Settings } from '@lucide/vue'
import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarGroup,
  SidebarGroupContent,
  SidebarGroupLabel,
  SidebarHeader,
  SidebarMenu,
  SidebarMenuBadge,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarProvider,
  SidebarRail,
  SidebarTrigger,
} from '@/components/ui/sidebar'

const main = [
  { label: 'Dashboard', href: '#dashboard', icon: LayoutDashboard },
  { label: 'Integrations', href: '#integrations', icon: Blocks, current: true },
  { label: 'Sync jobs', href: '#jobs', icon: ArrowLeftRight, count: 3 },
  { label: 'Logs', href: '#logs', icon: ScrollText },
]
</script>

<template>
  <!-- In an app the provider fills the window. Here it is held in a box: the side navigation is placed
       absolute instead of fixed, and isolate keeps it under the page's own header. -->
  <SidebarProvider class="isolate relative min-h-[26rem] w-full overflow-hidden rounded-(--bh-radius-card) border-(length:--bh-border-width-default) border-(--bh-color-border)">
    <Sidebar collapsible="icon" class="absolute h-full">
      <SidebarHeader>
        <span class="flex h-(--bh-size-control-default) items-center truncate px-(--bh-space-150) text-(--bh-color-text) [font:var(--bh-font-heading-xsmall)] group-data-[collapsible=icon]:invisible">ERP sync</span>
      </SidebarHeader>
      <SidebarContent>
        <SidebarGroup>
          <SidebarGroupLabel>Workspace</SidebarGroupLabel>
          <SidebarGroupContent>
            <SidebarMenu>
              <SidebarMenuItem v-for="item in main" :key="item.href">
                <SidebarMenuButton as-child :is-active="item.current" :tooltip="item.label">
                  <a :href="item.href">
                    <component :is="item.icon" aria-hidden="true" />
                    <span>{{ item.label }}</span>
                  </a>
                </SidebarMenuButton>
                <SidebarMenuBadge v-if="item.count">{{ item.count }}</SidebarMenuBadge>
              </SidebarMenuItem>
            </SidebarMenu>
          </SidebarGroupContent>
        </SidebarGroup>
      </SidebarContent>
      <SidebarFooter>
        <SidebarMenu>
          <SidebarMenuItem>
            <SidebarMenuButton as-child tooltip="Settings">
              <a href="#settings">
                <Settings aria-hidden="true" />
                <span>Settings</span>
              </a>
            </SidebarMenuButton>
          </SidebarMenuItem>
        </SidebarMenu>
      </SidebarFooter>
      <SidebarRail />
    </Sidebar>
    <!-- In an app this is SidebarInset, the page's <main>. A div here: this site already has one. -->
    <div class="flex min-w-0 flex-1 flex-col bg-(--bh-color-surface-page)">
      <header class="flex h-(--bh-layout-header-height) items-center gap-(--bh-space-100) border-b-(length:--bh-border-width-default) border-(--bh-color-border) px-(--bh-space-200)">
        <SidebarTrigger />
        <span class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Integrations</span>
      </header>
      <p class="m-0 p-(--bh-space-200) text-(--bh-color-text-subtle)">
        Collapse the navigation with the button, the edge strip or Ctrl+B. In the rail, each label shows in a tooltip.
      </p>
    </div>
  </SidebarProvider>
</template>

With sub-pages

Sub-pages sit under their parent.

SidebarSubmenu.vue
<script setup lang="ts">
import { Blocks, LayoutDashboard, ScrollText } from '@lucide/vue'
import {
  Sidebar,
  SidebarContent,
  SidebarGroup,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarMenuSub,
  SidebarMenuSubButton,
  SidebarMenuSubItem,
  SidebarProvider,
} from '@/components/ui/sidebar'

// collapsible="none": always open, no rail and no drawer. Sub-pages sit under their parent.
const connections = [
  { label: 'Online store', href: '#online-store', current: true },
  { label: 'ERP', href: '#erp' },
  { label: 'CRM', href: '#crm' },
]
</script>

<template>
  <SidebarProvider class="min-h-0 w-auto">
    <Sidebar collapsible="none" class="border-e-(length:--bh-border-width-default) border-(--bh-color-border)">
      <SidebarContent>
        <SidebarGroup>
          <SidebarMenu>
            <SidebarMenuItem>
              <SidebarMenuButton as-child>
                <a href="#dashboard"><LayoutDashboard aria-hidden="true" /><span>Dashboard</span></a>
              </SidebarMenuButton>
            </SidebarMenuItem>
            <SidebarMenuItem>
              <SidebarMenuButton as-child>
                <a href="#integrations"><Blocks aria-hidden="true" /><span>Integrations</span></a>
              </SidebarMenuButton>
              <SidebarMenuSub>
                <SidebarMenuSubItem v-for="item in connections" :key="item.href">
                  <SidebarMenuSubButton :href="item.href" :is-active="item.current">
                    <span>{{ item.label }}</span>
                  </SidebarMenuSubButton>
                </SidebarMenuSubItem>
              </SidebarMenuSub>
            </SidebarMenuItem>
            <SidebarMenuItem>
              <SidebarMenuButton as-child>
                <a href="#logs"><ScrollText aria-hidden="true" /><span>Logs</span></a>
              </SidebarMenuButton>
            </SidebarMenuItem>
          </SidebarMenu>
        </SidebarGroup>
      </SidebarContent>
    </Sidebar>
  </SidebarProvider>
</template>