---
title: "ContentNavigation"
description: "Навигация по страницам в виде аккордеона: разделы документации и вложенные ссылки."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/content-navigation"
---
# ContentNavigation

> Навигация по страницам в виде аккордеона: разделы документации и вложенные ссылки.

> [!WARNING]
> See: /docs/getting-started/integrations/content/
> Компонент доступен, только если установлен модуль `@nuxt/content`.

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

Пропс `navigation` принимает `navigation` — то, что возвращает запрос навигации приложения.

```vue [ContentNavigationExample.vue]
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'
import { withTrailingSlash } from 'ufo'

const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')

// The docs site serves every page with a trailing slash (`useNavigation` adds it in place,
// on the client only); copying the tree with the slash keeps SSR and hydration in step.
const withSlash = (items: ContentNavigationItem[] = []): ContentNavigationItem[] => items.map(item => ({
  ...item,
  path: withTrailingSlash(item.path),
  children: item.children && withSlash(item.children)
}))

const links = computed(() => withSlash(navigation?.value))
</script>

<template>
  <B24ContentNavigation :navigation="links" highlight />
</template>
```

### Тип

Пропс `type` со значением `single` оставляет открытым только один раздел. По умолчанию — `multiple`.

```vue
<script setup lang="ts">
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: "Руководство",
    icon: "i-bx24-crm-book-open",
    path: "#getting-started",
    children: [
      {
        title: "Введение",
        path: "#introduction",
        active: true
      },
      {
        title: "Установка",
        path: "#installation"
      }
    ]
  },
  {
    title: "Композаблы",
    icon: "i-bx24-outline-database",
    path: "#composables",
    children: [
      {
        title: "defineShortcuts",
        path: "#defineshortcuts"
      },
      {
        title: "useOverlay",
        path: "#useoverlay"
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation type="single" />
</template>
```

### Цвет

Пропс `color` задаёт цвет активной ссылки.

```vue
<script setup lang="ts">
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: "Руководство",
    icon: "i-bx24-crm-book-open",
    path: "#getting-started",
    children: [
      {
        title: "Введение",
        path: "#introduction",
        active: true
      },
      {
        title: "Установка",
        path: "#installation"
      }
    ]
  },
  {
    title: "Композаблы",
    icon: "i-bx24-outline-database",
    path: "#composables",
    children: [
      {
        title: "defineShortcuts",
        path: "#defineshortcuts"
      },
      {
        title: "useOverlay",
        path: "#useoverlay"
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation color="air-primary-success" />
</template>
```

### Вариант

Пропс `variant` меняет вид ссылок: `pill` — активная ссылка на подложке, `link` — без подложки.

```vue
<script setup lang="ts">
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: "Руководство",
    icon: "i-bx24-crm-book-open",
    path: "#getting-started",
    children: [
      {
        title: "Введение",
        path: "#introduction",
        active: true
      },
      {
        title: "Установка",
        path: "#installation"
      }
    ]
  },
  {
    title: "Композаблы",
    icon: "i-bx24-outline-database",
    path: "#composables",
    children: [
      {
        title: "defineShortcuts",
        path: "#defineshortcuts"
      },
      {
        title: "useOverlay",
        path: "#useoverlay"
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation variant="link" />
</template>
```

### Подсветка

Пропс `highlight` рисует линию рядом с активной ссылкой.

Пропс `highlight-color` задаёт цвет линии. По умолчанию он равен `color`.

```vue
<script setup lang="ts">
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: "Руководство",
    icon: "i-bx24-crm-book-open",
    path: "#getting-started",
    children: [
      {
        title: "Введение",
        path: "#introduction",
        active: true
      },
      {
        title: "Установка",
        path: "#installation"
      }
    ]
  },
  {
    title: "Композаблы",
    icon: "i-bx24-outline-database",
    path: "#composables",
    children: [
      {
        title: "defineShortcuts",
        path: "#defineshortcuts"
      },
      {
        title: "useOverlay",
        path: "#useoverlay"
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation highlight highlight-color="air-primary" color="air-primary" variant="pill" />
</template>
```

### Значок раскрытия

Пропс `trailing-icon` задаёт [иконку](https://bitrix24.github.io/b24icons/icons/) у разделов с вложенными ссылками. По умолчанию — `i-bx24-outline-chevron-down-l`.

```vue
<script setup lang="ts">
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: "Руководство",
    icon: "i-bx24-crm-book-open",
    path: "#getting-started",
    children: [
      {
        title: "Введение",
        path: "#introduction",
        active: true
      },
      {
        title: "Установка",
        path: "#installation"
      }
    ]
  },
  {
    title: "Композаблы",
    icon: "i-bx24-outline-database",
    path: "#composables",
    children: [
      {
        title: "defineShortcuts",
        path: "#defineshortcuts"
      },
      {
        title: "useOverlay",
        path: "#useoverlay"
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation trailing-icon="i-bx24-actions-arrow-to-the-top" />
</template>
```

> [!TIP]
> See: /docs/getting-started/integrations/icons/nuxt/#set-of-icons
> Значок по умолчанию — ключ `chevronDown` набора иконок.

## Примеры

### В макете

Компонент ставится в [PageAside](https://b24-ui.bx-shef.by/raw/docs/components/page-aside.md) макета и показывает навигацию по страницам:

```vue [layouts/docs.vue]
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
</script>

<template>
  <B24Page>
    <template #left>
      <B24PageAside>
        <B24ContentNavigation :navigation="navigation" highlight />
      </B24PageAside>
    </template>

    <slot />
  </B24Page>
</template>
```

### В шапке

В слоте `body` компонента [Header](https://b24-ui.bx-shef.by/raw/docs/components/header.md) навигация видна на телефоне:

```vue [components/Header.vue]
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
</script>

<template>
  <B24Header>
    <template #body>
      <B24ContentNavigation :navigation="navigation" highlight />
    </template>
  </B24Header>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the ContentNavigation component
 */
interface ContentNavigationProps {
  /**
   * The element or component this component should render as.
   * @default 'nav'
   */
  as?: any;
  /**
   * When `true`, the tree will be opened based on the current route.
   * When `false`, the tree will be closed.
   * When `undefined` (default), the first item will be opened with `type="single"` and the first level will be opened with `type="multiple"`.
   * @default undefined
   */
  defaultOpen?: boolean | undefined;
  /**
   * The icon displayed to toggle the accordion.
   * @default icons.chevronDown
   */
  trailingIcon?: IconProp | undefined;
  /**
   * @default 'air-primary'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-primary-no-accent";
  /**
   * @default 'pill'
   */
  variant?: "pill" | "link" | undefined;
  /**
   * Display a line next to the active link.
   * @default false
   */
  highlight?: boolean | undefined;
  /**
   * @default 'air-primary'
   */
  highlightColor?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-copilot" | "air-primary-warning" | "air-primary-no-accent" | undefined;
  /**
   * When type is "single", prevents closing the open item when clicking its trigger.
   * When type is "multiple", disables the collapsible behavior.
   * @default true
   */
  collapsible?: boolean | undefined;
  /**
   * @default 0
   */
  level?: number | undefined;
  navigation?: T[] | undefined;
  b24ui?: { root?: SlotClass; content?: SlotClass; list?: SlotClass; item?: SlotClass; listWithChildren?: SlotClass; itemWithChildren?: SlotClass; trigger?: SlotClass; link?: SlotClass; linkLeadingIcon?: SlotClass; linkTrailing?: SlotClass; linkTrailingBadge?: SlotClass; linkTrailingBadgeSize?: SlotClass; linkTrailingIcon?: SlotClass; linkTitle?: SlotClass; linkTitleExternalIcon?: SlotClass; } | undefined;
  /**
   * When `true`, prevents the user from interacting with the accordion and all its items
   * @default false
   */
  disabled?: boolean | undefined;
  /**
   * Determines whether a "single" or "multiple" items can be selected at a time.
   * 
   * This prop will overwrite the inferred type from `modelValue` and `defaultValue`.
   * @default 'multiple'
   */
  type?: "single" | "multiple" | undefined;
  /**
   * When `true`, the element will be unmounted on closed state.
   * @default true
   */
  unmountOnHide?: boolean | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the ContentNavigation component
 */
interface ContentNavigationSlots {
  link(): any;
  link-leading(): any;
  link-title(): any;
  link-trailing(): any;
}
```

### События

```ts
/**
 * Emitted events for the ContentNavigation component
 */
interface ContentNavigationEmits {
  update:modelValue: (payload: [value: string | string[] | undefined]) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    contentNavigation: {
      slots: {
        root: '',
        content: 'motion-safe:data-[state=open]:animate-[accordion-down_200ms_var(--ease-out)] motion-safe:data-[state=closed]:animate-[accordion-up_200ms_var(--ease-out)] data-[state=closed]:overflow-hidden focus:outline-none',
        list: 'isolate -mx-2.5 -mt-1.5',
        item: '',
        listWithChildren: 'ms-5 border-s border-(--ui-color-divider-default)',
        itemWithChildren: 'flex flex-col data-[state=open]:mb-1.5',
        trigger: 'font-(--ui-font-weight-semi-bold)',
        link: 'group relative w-full px-2.5 py-1.5 flex items-center gap-1.5 text-(length:--ui-font-size-md) before:absolute before:inset-y-px before:inset-x-0 before:z-[-1] before:rounded-(--ui-border-radius-sm) focus:outline-none focus-visible:outline-none focus-visible:before:outline-3 focus-visible:before:outline-(--ui-color-design-outline-focused-stroke)',
        linkLeadingIcon: 'shrink-0 size-5',
        linkTrailing: 'ms-auto inline-flex gap-1.5 items-center',
        linkTrailingBadge: 'shrink-0',
        linkTrailingBadgeSize: 'sm',
        linkTrailingIcon: 'size-5 transform transition-transform duration-200 ease-out motion-reduce:transition-none shrink-0 group-data-[state=open]:rotate-180 text-(--ui-color-design-plain-content-icon-secondary)',
        linkTitle: 'truncate',
        linkTitleExternalIcon: 'inline-block size-3 align-top text-(--ui-color-design-plain-content-icon-secondary)'
      },
      variants: {
        color: {
          'air-primary': {
            root: 'style-filled'
          },
          'air-primary-success': {
            root: 'style-filled-success'
          },
          'air-primary-alert': {
            root: 'style-filled-alert'
          },
          'air-primary-copilot': {
            root: 'style-filled-copilot'
          },
          'air-primary-warning': {
            root: 'style-filled-warning'
          },
          'air-primary-no-accent': {
            root: 'style-filled-no-accent'
          }
        },
        highlightColor: {
          'air-primary': '',
          'air-primary-success': '',
          'air-primary-alert': '',
          'air-primary-copilot': '',
          'air-primary-warning': '',
          'air-primary-no-accent': ''
        },
        variant: {
          pill: '',
          link: ''
        },
        active: {
          true: {
            link: 'font-(--ui-font-weight-medium)'
          },
          false: {
            link: 'text-description',
            linkLeadingIcon: 'text-(--ui-color-design-plain-content-icon-secondary)'
          }
        },
        disabled: {
          true: {
            trigger: 'data-[state=open]:text-legend'
          }
        },
        highlight: {
          true: {}
        },
        level: {
          true: {
            item: 'ps-1.5 -ms-px',
            itemWithChildren: 'ps-1.5 -ms-px'
          }
        }
      },
      compoundVariants: [
        {
          highlight: true,
          level: true,
          class: {
            link: 'after:absolute after:-start-1.5 after:inset-y-0.5 after:block after:w-px after:rounded-full after:transition-colors'
          }
        },
        {
          disabled: false,
          active: false,
          variant: 'pill',
          class: {
            link: 'hover:text-legend data-[state=open]:text-legend hover:before:bg-(--ui-color-base-black-fixed)/3 dark:hover:before:bg-(--ui-color-base-black-fixed) transition-colors before:transition-colors',
            linkLeadingIcon: 'group-hover:text-label group-data-[state=open]:text-label transition-colors'
          }
        },
        {
          color: [
            'air-primary',
            'air-primary-success',
            'air-primary-alert',
            'air-primary-copilot',
            'air-primary-warning'
          ],
          active: true,
          class: {
            link: 'text-(--b24ui-background)',
            linkLeadingIcon: 'text-(--b24ui-background) group-data-[state=open]:text-(--b24ui-background)'
          }
        },
        {
          color: 'air-primary-no-accent',
          active: true,
          class: {
            link: 'text-legend',
            linkLeadingIcon: 'text-legend group-data-[state=open]:text-legend'
          }
        },
        {
          variant: 'pill',
          active: true,
          highlight: false,
          class: {
            link: 'before:bg-(--ui-color-design-selection-bg)'
          }
        },
        {
          variant: 'pill',
          active: true,
          highlight: true,
          disabled: false,
          class: {
            link: 'hover:before:bg-(--ui-color-base-black-fixed)/3 dark:hover:before:bg-(--ui-color-base-black-fixed) before:transition-colors'
          }
        },
        {
          disabled: false,
          active: false,
          variant: 'link',
          class: {
            link: 'hover:text-legend data-[state=open]:text-legend transition-colors',
            linkLeadingIcon: 'group-hover:text-label group-data-[state=open]:text-label transition-colors'
          }
        },
        {
          highlightColor: 'air-primary',
          highlight: true,
          level: true,
          active: true,
          class: {
            link: 'after:bg-(--ui-color-design-filled-bg)'
          }
        },
        {
          highlightColor: 'air-primary-success',
          highlight: true,
          level: true,
          active: true,
          class: {
            link: 'after:bg-(--ui-color-design-filled-success-bg)'
          }
        },
        {
          highlightColor: 'air-primary-alert',
          highlight: true,
          level: true,
          active: true,
          class: {
            link: 'after:bg-(--ui-color-design-filled-alert-bg)'
          }
        },
        {
          highlightColor: 'air-primary-copilot',
          highlight: true,
          level: true,
          active: true,
          class: {
            link: 'after:bg-(--ui-color-design-filled-copilot-bg)'
          }
        },
        {
          highlightColor: 'air-primary-warning',
          highlight: true,
          level: true,
          active: true,
          class: {
            link: 'after:bg-(--ui-color-design-filled-warning-bg)'
          }
        },
        {
          highlightColor: 'air-primary-no-accent',
          highlight: true,
          level: true,
          active: true,
          class: {
            link: 'after:bg-(--b24ui-typography-legend-color)'
          }
        }
      ],
      defaultVariants: {
        color: 'air-primary',
        highlightColor: 'air-primary',
        variant: 'pill'
      }
    }
  }
})
```

## Sitemap

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