Accordion
Usage
Items
Use the items
prop as an array of objects with the following properties:
label?: string
icon?: FunctionalComponent<HTMLAttributes & VNodeProps>
trailingIcon?: FunctionalComponent<HTMLAttributes & VNodeProps>
content?: string
value?: string
disabled?: boolean
slot?: string
class?: any
b24ui?: { item?: ClassNameValue, header?: ClassNameValue, trigger?: ClassNameValue, leadingIcon?: ClassNameValue, label?: ClassNameValue, trailingIcon?: ClassNameValue, content?: ClassNameValue, body?: ClassNameValue }
<script setup lang="ts">
import { ref } from 'vue'
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
const items = ref<AccordionItem[]>([
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.'
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
])
</script>
<template>
<B24Accordion :items="items" />
</template>
Multiple
Set the type
prop to multiple
to allow multiple items to be active at the same time. Defaults to single
.
Details
<script setup lang="ts">
import { ref } from 'vue'
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
const items = ref<AccordionItem[]>([
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.'
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
])
</script>
<template>
<B24Accordion
:items="items"
type="multiple"
/>
</template>
Collapsible
When type
is single
, you can set the collapsible
prop to false
to prevent the active item from collapsing.
Details
<script setup lang="ts">
import { ref } from 'vue'
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
const items = ref<AccordionItem[]>([
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.'
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
])
</script>
<template>
<B24Accordion
:items="items"
:collapsible="false"
/>
</template>
Unmount
Use the unmount-on-hide
prop to prevent the content from being unmounted when the accordion is collapsed. Defaults to true
.
INFO
You can inspect the DOM to see each item's content being rendered.
Details
<script setup lang="ts">
import { ref } from 'vue'
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
export interface ExampleProps {
isUnmountOnHide?: boolean
}
withDefaults(defineProps<ExampleProps>(), {
isUnmountOnHide: true
})
const items = ref<AccordionItem[]>([
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.'
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
])
</script>
<template>
<B24Accordion
:items="items"
:unmount-on-hide="isUnmountOnHide"
/>
</template>
Disabled
Use the disabled
property to disable the Accordion.
You can also disable a specific item by using the disabled
property in the item object.
Details
<script setup lang="ts">
import { ref } from 'vue'
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
export interface ExampleProps {
isDisabled?: boolean
}
withDefaults(defineProps<ExampleProps>(), {
isDisabled: true
})
const items = ref<AccordionItem[]>([
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.',
disabled: true
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
])
</script>
<template>
<B24Accordion
:items="items"
:disabled="isDisabled"
/>
</template>
Trailing Icon
Use the trailing-icon
prop to customize the trailing @bitrix24/b24icons of each item. Defaults to Actions::ChevronDownIcon
.
INFO
You can also set an icon for a specific item by using the trailingIcon
property in the item object.
Details
<script setup lang="ts">
import { ref } from 'vue'
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
import PlusLIcon from '@bitrix24/b24icons-vue/outline/PlusLIcon'
const items = ref<AccordionItem[]>([
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.',
trailingIcon: PlusLIcon
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
])
</script>
<template>
<B24Accordion :items="items" />
</template>
Examples
Control active item(s)
You can control the active item(s) by using the default-value
prop or the v-model
directive with the index of the item.
INFO
You can also pass the value
of one of the items if provided.
WARNING
When type="multiple"
, ensure to pass an array to the default-value
prop or the v-model
directive.
Details
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
const items = ref<AccordionItem[]>([
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.'
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
])
const active = ref('0')
// Note: This is for demonstration purposes only. Don't do this at home.
onMounted(() => {
setInterval(() => {
active.value = String((Number(active.value) + 1) % items.value.length)
}, 2000)
})
</script>
<template>
<B24Accordion v-model="active" :items="items" />
</template>
With drag and drop
Use the useSortable
composable from @vueuse/integrations
to enable drag and drop functionality on the Accordion. This integration wraps Sortable.js to provide a seamless drag and drop experience.
Details
<script setup lang="ts">
import { shallowRef, useTemplateRef } from 'vue'
import { useSortable } from '@vueuse/integrations/useSortable'
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
const items = shallowRef<AccordionItem[]>([
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.'
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
])
const accordion = useTemplateRef<HTMLElement>('accordion')
useSortable(
accordion,
items,
{
animation: 150
}
)
</script>
<template>
<B24Accordion ref="accordion" :items="items" />
</template>
With body slot
Use the #body
slot to customize the body of each item.
INFO
The #body
slot includes some pre-defined styles, use the #content
slot if you want to start from scratch.
Details
<script setup lang="ts">
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
const items: AccordionItem[] = [
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon
}
]
</script>
<template>
<B24Accordion :items="items">
<template #body="{ item }">
This is the <ProseCode>{{ item.label }}</ProseCode> panel.
</template>
</B24Accordion>
</template>
With content slot
Use the #content
slot to customize the content of each item.
Details
<script setup lang="ts">
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
const items: AccordionItem[] = [
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon
}
]
</script>
<template>
<B24Accordion :items="items">
<template #content="{ item }">
<p class="pb-4 text-base-700 dark:text-base-300">
This is the <ProseCode>{{ item.label }}</ProseCode> panel.
</p>
</template>
</B24Accordion>
</template>
With custom slot
Use the slot
property to customize a specific item.
You will have access to the following slots:
#{{ item.slot }}
#{{ item.slot }}-body
Details
<script setup lang="ts">
import type { AccordionItem } from '@bitrix24/b24ui-nuxt'
import SmartActivityIcon from '@bitrix24/b24icons-vue/outline/SmartActivityIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import RocketIcon from '@bitrix24/b24icons-vue/outline/RocketIcon'
const items = [
{
label: 'Getting started with Bitrix24',
icon: SmartActivityIcon,
content: 'Bitrix24 is an online service that offers useful tools for your company. This includes chats and calls, tasks and projects, CRM, and AI-powered assistant.'
},
{
label: 'Main features of Bitrix24',
icon: FeedbackIcon,
slot: 'colors' as const,
content: 'Bitrix24 is an online service that has all the tools for company operation and business management.'
},
{
label: 'Bitrix24 Cloud plans',
icon: RocketIcon,
content: 'Bitrix24 is an online service for business management and work automation. It contains tools for companies of all sizes and industries. Bitrix24 has several plans with different sets of tools that are suitable for different types of business.'
}
] satisfies AccordionItem[]
</script>
<template>
<B24Accordion :items="items">
<template #colors="{ item }">
<p class="pb-4 text-red-500">
{{ item.content }}
</p>
</template>
</B24Accordion>
</template>
API
Props
Prop | Default | Type |
---|---|---|
as | 'div' | any The element or component this component should render as. |
items | AccordionItem[] | |
trailingIcon | icons.chevronDown | (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Data; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed) => void; }, "expose">): any The icon displayed on the right side of the trigger. |
labelKey | "label" | string The key used to get the label from the item. |
b24ui | { root?: ClassNameValue; item?: ClassNameValue; header?: ClassNameValue; trigger?: ClassNameValue; content?: ClassNameValue; body?: ClassNameValue; leadingIcon?: ClassNameValue; trailingIcon?: ClassNameValue; label?: ClassNameValue; } | |
collapsible | true | boolean When type is "single", allows closing content when clicking trigger for an open item.
When type is "multiple", this prop has no effect. |
defaultValue | string | string[] The default active value of the item(s).
Use when you do not need to control the state of the item(s). | |
modelValue | string | string[] The controlled value of the active item(s).
Use this when you need to control the state of the items. Can be binded with `v-model` | |
type | "single" | "single" | "multiple" Determines whether a "single" or "multiple" items can be selected at a time.
This prop will overwrite the inferred type from `modelValue` and `defaultValue`. |
disabled | false | boolean When `true`, prevents the user from interacting with the accordion and all its items |
unmountOnHide | true | boolean When `true`, the element will be unmounted on closed state. |
Slots
Slot | Type |
---|---|
leading | { item: AccordionItem; index: number; open: boolean; } |
default | { item: AccordionItem; index: number; open: boolean; } |
trailing | { item: AccordionItem; index: number; open: boolean; } |
content | { item: AccordionItem; index: number; open: boolean; } |
body | { item: AccordionItem; index: number; open: boolean; } |
Emits
Event | Type |
---|