---
title: "DashboardSidebar"
description: "Боковое меню дашборда с изменяемым размером и возможностью сворачивания."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/dashboard-sidebar"
---
# DashboardSidebar

> Боковое меню дашборда с изменяемым размером и возможностью сворачивания.

## Использование

Компонент DashboardSidebar показывает боковое меню. Его состояние (размер, свёрнутость и другое) сохраняется по пропсам `storage` и `storage-key` компонента [DashboardGroup](https://b24-ui.bx-shef.by/raw/docs/components/dashboard-group.md#props).

Используйте его в слоте по умолчанию компонента [DashboardGroup](https://b24-ui.bx-shef.by/raw/docs/components/dashboard-group.md):

```vue [layouts/dashboard.vue]
<template>
  <B24DashboardGroup>
    <B24DashboardSidebar />

    <slot />
  </B24DashboardGroup>
</template>
```

> [!WARNING]
> С пропсом `resizable` у компонента нет единого корневого элемента, поэтому при переходах между страницами или если нужен единый корень для раскладки, оберните его в контейнер (например, `<div class="flex flex-1">`).

Слоты `header`, `default` и `footer` настраивают боковое меню, а слоты `body` и `content` — его мобильное меню.

```vue [DashboardSidebarExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'
import SettingsIcon from '@bitrix24/b24icons-vue/outline/SettingsIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import InfoCircleIcon from '@bitrix24/b24icons-vue/outline/InfoCircleIcon'

const items: NavigationMenuItem[][] = [
  [
    {
      label: 'Главная',
      icon: HomeIcon,
      active: true
    },
    {
      label: 'Входящие',
      icon: MailIcon,
      badge: '4'
    },
    {
      label: 'Контакты',
      icon: ContactIcon
    },
    {
      label: 'Настройки',
      icon: SettingsIcon,
      defaultOpen: true,
      children: [
        {
          label: 'Общие'
        },
        {
          label: 'Участники'
        },
        {
          label: 'Уведомления'
        }
      ]
    }
  ],
  [
    {
      label: 'Обратная связь',
      icon: FeedbackIcon,
      to: 'https://github.com/bitrix24/b24ui/issues',
      target: '_blank'
    },
    {
      label: 'Помощь и поддержка',
      icon: InfoCircleIcon,
      to: 'https://github.com/bitrix24/b24ui',
      target: '_blank'
    }
  ]
]
</script>

<template>
  <B24DashboardSidebar
    collapsible
    resizable
    class="border-e-1"
  >
    <template #header="{ collapsed }">
      <Logo v-if="!collapsed" class="h-5 w-auto shrink-0 text-label" />
      <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
    </template>

    <template #default="{ collapsed }">
      <B24DashboardSearchButton :collapsed="collapsed" />

      <B24NavigationMenu
        :collapsed="collapsed"
        :items="items[0]"
        orientation="vertical"
      />

      <B24NavigationMenu
        :collapsed="collapsed"
        :items="items[1]"
        orientation="vertical"
        class="mt-auto"
      />
    </template>

    <template #footer="{ collapsed }">
      <B24Button
        :avatar="{
          src: 'https://github.com/bitrix24.png',
          loading: 'lazy' as const
        }"
        :label="collapsed ? undefined : 'Bitrix24'"
        class="w-full"
        :block="collapsed"
      />
    </template>
  </B24DashboardSidebar>
</template>
```

> [!NOTE]
> Чтобы свернуть меню, перетащите его к левому краю экрана.

### Изменяемый размер

Пропс `resizable` делает размер бокового меню изменяемым.

```vue
<template>
  <B24DashboardSidebar resizable>
<Placeholder class="ms-2 h-96" />
</B24DashboardSidebar>
</template>
```

### Сворачивание

Пропс `collapsible` позволяет сворачивать боковое меню, когда его перетаскивают к краю экрана.

> [!WARNING]
> Если боковое меню не **collapsible**, компонент [`DashboardSidebarCollapse`](https://b24-ui.bx-shef.by/raw/docs/components/dashboard-sidebar-collapse.md) ничего не сделает.

```vue
<template>
  <B24DashboardSidebar resizable collapsible>
<Placeholder class="ms-2 h-96" />
</B24DashboardSidebar>
</template>
```

> [!TIP]
> See: #slots
> Состояние `collapsed` доступно в слот-пропсах, поэтому содержимое свёрнутого меню можно настроить.

### Размер

Пропсы `min-size`, `max-size`, `default-size` и `collapsed-size` (в `px`) задают размер бокового меню.

```vue
<template>
  <B24DashboardSidebar resizable collapsible :min-size="200" :default-size="240" :max-size="250" :collapsed-size="66">
<Placeholder class="ms-2 h-96" />
</B24DashboardSidebar>
</template>
```

> [!TIP]
> See: /docs/components/dashboard-group/#props
> По умолчанию размеры считаются в процентах. Единицу меняет пропс `unit` компонента `DashboardGroup`.

> [!NOTE]
> По умолчанию `collapsed-size` равен `0`, но у бокового меню есть `min-w-16`, чтобы оно оставалось видимым.

### Сторона

Пропс `side` меняет сторону бокового меню. По умолчанию `left`.

```vue
<template>
  <B24DashboardSidebar side="right" resizable collapsible>
<Placeholder class="ms-2 h-96" />
</B24DashboardSidebar>
</template>
```

### Режим

Пропс `mode` меняет режим мобильного меню. По умолчанию `slideover`.

Слот `body` заполняет тело меню (под шапкой), слот `content` — всё меню целиком.

> [!TIP]
> See: #props
> Пропс `menu` настраивает мобильное меню бокового меню и подстраивается под выбранный режим.

```vue [DashboardSidebarModeExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

defineProps<{
  mode: 'drawer' | 'slideover' | 'modal'
}>()

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]
</script>

<template>
  <B24DashboardGroup>
    <B24DashboardSidebar
      :mode="mode"
    >
      <template #header="{ collapsed }">
        <Logo v-if="!collapsed" class="h-5 w-auto text-label" />
        <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
      </template>

      <B24NavigationMenu
        :items="items"
        orientation="vertical"
      />
    </B24DashboardSidebar>

    <B24DashboardPanel>
      <template #header>
        <B24DashboardNavbar title="Дашборд" class="bg-(--ui-color-design-outline-bg-alt) backdrop-blur-md" />
      </template>
    </B24DashboardPanel>
  </B24DashboardGroup>
</template>
```

> [!NOTE]
> В этих примерах есть компоненты [`DashboardGroup`](https://b24-ui.bx-shef.by/raw/docs/components/dashboard-group.md), [`DashboardPanel`](https://b24-ui.bx-shef.by/raw/docs/components/dashboard-panel.md) и [`DashboardNavbar`](https://b24-ui.bx-shef.by/raw/docs/components/dashboard-navbar.md): они нужны, чтобы показать боковое меню на мобильных устройствах.

### Кнопка переключения

Пропс `toggle` настраивает компонент [DashboardSidebarToggle](https://b24-ui.bx-shef.by/raw/docs/components/dashboard-sidebar-toggle.md), который показывается на мобильных устройствах.

Кнопку можно настроить любым свойством компонента [Button](https://b24-ui.bx-shef.by/raw/docs/components/button.md).

```vue [DashboardSidebarToggleExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]
</script>

<template>
  <B24DashboardGroup>
    <B24DashboardSidebar
      open
      :toggle="{
        color: 'air-primary',
        class: 'rounded-full'
      }"
    >
      <template #header>
        <Logo class="h-5 w-auto text-label" />
      </template>

      <B24NavigationMenu
        :items="items"
        orientation="vertical"
      />
    </B24DashboardSidebar>

    <B24DashboardPanel>
      <template #header>
        <B24DashboardNavbar title="Дашборд" class="bg-(--ui-color-design-outline-bg-alt) backdrop-blur-md" />
      </template>
    </B24DashboardPanel>
  </B24DashboardGroup>
</template>
```

### Сторона кнопки

Пропс `toggle-side` меняет сторону, с которой стоит кнопка переключения. По умолчанию `left`.

```vue [DashboardSidebarToggleSideExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]
</script>

<template>
  <B24DashboardGroup>
    <B24DashboardSidebar
      open
      toggle-side="right"
    >
      <template #header>
        <Logo class="h-5 w-auto text-label" />
      </template>

      <B24NavigationMenu
        :items="items"
        orientation="vertical"
      />
    </B24DashboardSidebar>

    <B24DashboardPanel>
      <template #header>
        <B24DashboardNavbar title="Дашборд" class="bg-(--ui-color-design-outline-bg-alt) backdrop-blur-md" />
      </template>
    </B24DashboardPanel>
  </B24DashboardGroup>
</template>
```

## Примеры

### Управление состоянием открытия

Состоянием открытия управляют пропс `open` или директива `v-model:open`.

> [!NOTE]
> В этом примере с помощью [`defineShortcuts`](https://b24-ui.bx-shef.by/raw/docs/composables/define-shortcuts.md) DashboardSidebar открывается и закрывается клавишей <kbd value="O">
> </kbd>
> .

```vue [DashboardSidebarOpenExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]

const open = ref(true)

defineShortcuts({
  o: () => open.value = !open.value
})
</script>

<template>
  <B24DashboardSidebar
    v-model:open="open"
  >
    <template #header="{ collapsed }">
      <Logo v-if="!collapsed" class="h-5 w-auto text-label" />
      <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
    </template>

    <B24NavigationMenu
      :items="items"
      orientation="vertical"
    />
  </B24DashboardSidebar>
</template>
```

### Управление состоянием сворачивания

Состоянием сворачивания управляют пропс `collapsed` или директива `v-model:collapsed`.

> [!NOTE]
> В этом примере с помощью [`defineShortcuts`](https://b24-ui.bx-shef.by/raw/docs/composables/define-shortcuts.md) DashboardSidebar сворачивается и разворачивается клавишей <kbd value="C">
> </kbd>
> .

```vue [DashboardSidebarCollapsedExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]

const collapsed = ref(false)

defineShortcuts({
  c: () => collapsed.value = !collapsed.value
})
</script>

<template>
  <B24DashboardSidebar
    v-model:collapsed="collapsed"
    collapsible
    class="border-e-1"
  >
    <template #header>
      <Logo v-if="!collapsed" class="h-5 w-auto text-label" />
      <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
    </template>

    <B24NavigationMenu
      :collapsed="collapsed"
      :items="items"
      orientation="vertical"
    />
  </B24DashboardSidebar>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the DashboardSidebar component
 */
interface DashboardSidebarProps {
  /**
   * The mode of the sidebar menu.
   * @default 'slideover'
   */
  mode?: T | undefined;
  /**
   * The props for the sidebar menu component.
   */
  menu?: DashboardSidebarMenu<T> | undefined;
  /**
   * Customize the toggle button to open the sidebar.
   * `{ color: 'air-tertiary' }`
   * @default true
   */
  toggle?: boolean | Omit<ButtonProps, LinkPropsKeys> | undefined;
  /**
   * The side to render the toggle button on.
   * @default 'left'
   */
  toggleSide?: "left" | "right" | undefined;
  /**
   * Automatically close when route changes.
   * @default true
   */
  autoClose?: boolean | undefined;
  b24ui?: { root?: SlotClass; header?: SlotClass; body?: SlotClass; footer?: SlotClass; toggle?: SlotClass; handle?: SlotClass; content?: SlotClass; overlay?: SlotClass; } | undefined;
  /**
   * The id of the panel.
   * @default useId()
   */
  id?: string | undefined;
  /**
   * The side to render the panel on.
   * @default 'left'
   */
  side?: "left" | "right" | undefined;
  /**
   * The minimum size of the panel.
   * @default 200
   */
  minSize?: number | undefined;
  /**
   * The maximum size of the panel.
   * @default 250
   */
  maxSize?: number | undefined;
  /**
   * The default size of the panel.
   * @default 240
   */
  defaultSize?: number | undefined;
  /**
   * Whether to allow the user to resize the panel.
   * @default false
   */
  resizable?: boolean | undefined;
  /**
   * Whether to allow the user to collapse the panel.
   * `collapse()` and `isCollapsed` do nothing while this is off.
   * @default false
   */
  collapsible?: boolean | undefined;
  /**
   * The size of the panel when collapsed.
   * @default 66
   */
  collapsedSize?: number | undefined;
  /**
   * @default false
   */
  open?: boolean | undefined;
  /**
   * @default false
   */
  collapsed?: boolean | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the DashboardSidebar component
 */
interface DashboardSidebarSlots {
  header(): any;
  default(): any;
  footer(): any;
  toggle(): any;
  content(): any;
  resize-handle(): any;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    dashboardSidebar: {
      slots: {
        root: 'relative hidden lg:flex flex-col min-h-svh min-w-16 w-(--width) shrink-0 backdrop-blur-sm bg-(--ui-color-bg-content-primary)/20 light:bg-transparent dark:bg-(--ui-color-bg-content-primary)/70 light:bg-transparent',
        header: 'h-(--b24ui-header-height) shrink-0 flex items-center gap-1.5 ps-4 pe-4',
        body: [
          'flex flex-col gap-4 flex-1 overflow-y-auto py-2 ps-4 pe-4 md:pe-2 scrollbar-thin scrollbar-transparent',
          'light:[--leftmenu-group-stroke:var(--ui-color-base-30)]'
        ],
        footer: 'shrink-0 flex items-center gap-1.5 py-2 ps-4 pe-4 lg:border-t lg:border-(--ui-color-divider-default) light:lg:border-(--ui-color-base-30)',
        toggle: '',
        handle: '',
        content: 'lg:hidden',
        overlay: 'lg:hidden'
      },
      variants: {
        menu: {
          true: {
            header: 'sm:px-6',
            body: 'sm:px-6',
            footer: 'sm:px-6'
          }
        },
        side: {
          left: {
            root: ''
          },
          right: {
            root: ''
          }
        },
        toggleSide: {
          left: {
            toggle: ''
          },
          right: {
            toggle: 'ms-auto'
          }
        }
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
