Usage
The Sidebar component is a standalone, fixed sidebar that pushes the page content. On desktop, it renders inline and can be collapsed; on mobile, it opens a Modal, Slideover or Drawer component.
Use the header, default and footer slots to customize the sidebar content. The v-model:open directive is viewport-aware: on desktop it controls the expanded/collapsed state, on mobile it controls the menu.
Variant
Use the variant prop to change the visual style of the sidebar. Defaults to sidebar.
Collapsible
Use the collapsible prop to change the collapse behavior of the sidebar. Defaults to offcanvas.
offcanvas: The sidebar slides out of view completely.icon: The sidebar shrinks to icon-only width.none: The sidebar is not collapsible.
state in the slot props to customize the content of the sidebar when it is collapsed.Side
Use the side prop to change the side of the sidebar. Defaults to left.
Title
Use the title prop to set the title of the sidebar header.
<template>
<B24Sidebar title="Navigation">
<Placeholder class="h-full" />
</B24Sidebar>
</template>
Description
Use the description prop to set the description of the sidebar header.
<template>
<B24Sidebar title="Navigation" description="Browse your workspace">
<Placeholder class="h-full" />
</B24Sidebar>
</template>
Rail
Use the rail prop to display a thin interactive edge on the sidebar that toggles the collapsed state on click. The rail is only rendered when collapsible is not none.
<template>
<B24Sidebar rail collapsible="icon" title="Navigation">
<Placeholder class="h-full" />
</B24Sidebar>
</template>
Close
Use the close prop to display a close button in the sidebar header. The close button is only rendered when collapsible is not none.
You can pass any property from the Button component to customize it.
<template>
<B24Sidebar close rail collapsible="icon" title="Navigation">
<Placeholder class="h-full" />
</B24Sidebar>
</template>
Close Icon
Use the close-icon prop to customize the close button Icon.
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>
<template>
<B24Sidebar
close
:close-icon="RocketIcon"
rail
collapsible="icon"
side="right"
title="Navigation"
>
<Placeholder class="h-full" />
</B24Sidebar>
</template>
Breakpoint 2.15+
Use the breakpoint prop to change the breakpoint below which the sidebar renders as a menu. Defaults to lg.
<template>
<B24Sidebar breakpoint="xl" />
</template>
--breakpoint-* values are not picked up.Mode
Use the mode prop to change the mode of the sidebar menu on mobile. Defaults to slideover.
menu prop to customize the menu of the sidebar, it will adapt depending on the mode you choose.Examples
Control open state
You can control the open state by using the open prop or the v-model:open directive. On desktop it controls the expanded/collapsed state, on mobile it opens/closes the sheet menu.
defineShortcuts, you can toggle the open state of the Sidebar by pressing O.Persist open state
Use useLocalStorage from VueUse or useCookie instead of ref to persist the sidebar state across page reloads.
ref(true) with useLocalStorage('sidebar-open', true).With custom width
The sidebar width is controlled by the --sidebar-width CSS variable (defaults to 16rem). The collapsed icon width is controlled by --sidebar-width-icon (defaults to 4rem).
Override them globally in your CSS or per-instance with the style attribute.
With header
To position the sidebar below a Header, customize the gap and container using the b24ui prop.
--b24ui-header-height variable defaults to 3.625rem and is used by the Header. Adjust it if your navbar uses a different height.With AI chat
Use the sidebar on the right side with ChatMessages and ChatPrompt to create an AI chat panel.
API
Props
Slots
Theme
export default {
slots: {
root: 'peer [--sidebar-width:15rem] [--sidebar-width-icon:4.5rem]',
gap: 'relative w-(--sidebar-width) bg-transparent',
container: 'fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width)',
inner: 'flex size-full flex-col overflow-hidden divide-y divide-default',
header: 'flex items-center gap-1.5 overflow-hidden px-4 min-h-(--b24ui-header-height)',
wrapper: 'min-w-0 flex-1',
title: 'text-label font-semibold truncate',
description: 'text-muted text-sm truncate',
actions: 'flex items-center gap-1.5 shrink-0',
close: '',
body: 'flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4',
footer: 'flex items-center gap-1.5 overflow-hidden p-4',
rail: 'absolute inset-y-0 z-20 hidden w-4 after:absolute after:inset-y-0 after:left-1/2 after:w-px hover:after:bg-(--ui-color-divider-accent) after:transition-colors',
content: '',
overlay: ''
},
variants: {
transition: {
true: {
gap: 'transition-[width] duration-200 ease-out motion-reduce:transition-none',
container: 'transition-[inset-inline-start,inset-inline-end,width] duration-200 ease-out motion-reduce:transition-none',
rail: 'transition-all ease-out'
}
},
breakpoint: {
sm: {
container: 'sm:flex',
rail: 'sm:flex'
},
md: {
container: 'md:flex',
rail: 'md:flex'
},
lg: {
container: 'lg:flex',
rail: 'lg:flex'
},
xl: {
container: 'xl:flex',
rail: 'xl:flex'
},
'2xl': {
container: '2xl:flex',
rail: '2xl:flex'
}
},
side: {
left: {
container: 'start-0 border-e border-default',
rail: 'end-0 translate-x-1/2 rtl:-translate-x-1/2'
},
right: {
container: 'end-0 border-s border-default',
rail: '-start-px -translate-x-1/2 rtl:translate-x-1/2'
}
},
collapsible: {
offcanvas: {
root: 'group/sidebar hidden',
gap: 'data-[state=collapsed]:w-0'
},
icon: {
root: 'group/sidebar hidden',
gap: 'data-[state=collapsed]:w-(--sidebar-width-icon)',
container: 'data-[state=collapsed]:w-(--sidebar-width-icon)',
actions: 'group-data-[state=collapsed]/sidebar:hidden',
body: 'group-data-[state=collapsed]/sidebar:overflow-hidden'
},
none: {
root: 'h-full w-(--sidebar-width)'
}
},
variant: {
sidebar: {},
floating: {
container: 'p-4 border-transparent',
inner: 'rounded-lg ring ring-default shadow-lg',
rail: 'inset-y-4'
},
inset: {
container: 'py-4 border-transparent',
inner: 'divide-transparent',
rail: 'inset-y-4'
}
}
},
compoundVariants: [
{
breakpoint: 'sm',
collapsible: [
'offcanvas',
'icon'
],
class: {
root: 'sm:block'
}
},
{
breakpoint: 'md',
collapsible: [
'offcanvas',
'icon'
],
class: {
root: 'md:block'
}
},
{
breakpoint: 'lg',
collapsible: [
'offcanvas',
'icon'
],
class: {
root: 'lg:block'
}
},
{
breakpoint: 'xl',
collapsible: [
'offcanvas',
'icon'
],
class: {
root: 'xl:block'
}
},
{
breakpoint: '2xl',
collapsible: [
'offcanvas',
'icon'
],
class: {
root: '2xl:block'
}
},
{
side: 'left',
collapsible: [
'offcanvas',
'icon'
],
class: {
rail: 'cursor-w-resize rtl:cursor-e-resize data-[state=collapsed]:cursor-e-resize data-[state=collapsed]:rtl:cursor-w-resize'
}
},
{
side: 'right',
collapsible: [
'offcanvas',
'icon'
],
class: {
rail: 'cursor-e-resize rtl:cursor-w-resize data-[state=collapsed]:cursor-w-resize data-[state=collapsed]:rtl:cursor-e-resize'
}
},
{
side: 'left',
collapsible: 'none',
class: {
root: 'border-e border-default'
}
},
{
side: 'right',
collapsible: 'none',
class: {
root: 'border-s border-default'
}
},
{
side: 'left',
collapsible: 'offcanvas',
class: {
container: 'data-[state=collapsed]:-start-(--sidebar-width)'
}
},
{
side: 'right',
collapsible: 'offcanvas',
class: {
container: 'data-[state=collapsed]:-end-(--sidebar-width)'
}
},
{
variant: 'floating',
collapsible: 'icon',
class: {
gap: 'data-[state=collapsed]:w-[calc(var(--sidebar-width-icon)+--spacing(6.5))]',
container: 'data-[state=collapsed]:w-[calc(var(--sidebar-width-icon)+--spacing(6.5)+2px)]'
}
},
{
variant: 'floating',
collapsible: 'none',
class: {
root: 'p-4 border-0'
}
},
{
variant: 'inset',
collapsible: 'none',
class: {
root: 'py-4 border-0'
}
},
{
variant: 'floating',
side: 'left',
class: {
rail: 'end-4'
}
},
{
variant: 'floating',
side: 'right',
class: {
rail: 'start-[calc(--spacing(4)-1px)]'
}
}
]
}