Использование
Директива v-model управляет значением Listbox, а пропс default-value задаёт начальное значение, когда управлять состоянием не нужно.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
},
{
label: 'Netherlands',
value: 'NL'
},
{
label: 'Poland',
value: 'PL'
},
{
label: 'Belgium',
value: 'BE'
},
{
label: 'Portugal',
value: 'PT'
},
{
label: 'Austria',
value: 'AT'
}
])
const value = ref({
label: 'France',
value: 'FR'
})
</script>
<template>
<B24Listbox v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
},
{
label: 'Netherlands',
value: 'NL'
},
{
label: 'Poland',
value: 'PL'
},
{
label: 'Belgium',
value: 'BE'
},
{
label: 'Portugal',
value: 'PT'
},
{
label: 'Austria',
value: 'AT'
}
])
const value = ref({
label: 'France',
value: 'FR'
})
</script>
<template>
<B24Listbox v-model="value" :items="items" />
</template>
Элементы
Пропс items — массив объектов со свойствами:
label?: stringdescription?: stringtype?: "label" | "separator" | "item"icon?: IconComponentavatar?: AvatarPropschip?: ChipPropsdisabled?: booleanonSelect?: (e: Event) => voidclass?: anyb24ui?: { label?: ClassNameValue, separator?: ClassNameValue, item?: ClassNameValue, itemLeadingIcon?: ClassNameValue, ... }
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
description: 'The Hexagon',
value: 'FR'
},
{
label: 'Germany',
description: 'The Federal Republic',
value: 'DE'
},
{
label: 'Italy',
description: 'The Boot',
value: 'IT'
},
{
label: 'Spain',
description: 'The Bull Skin',
value: 'ES'
}
])
</script>
<template>
<B24Listbox :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
description: 'The Hexagon',
value: 'FR'
},
{
label: 'Germany',
description: 'The Federal Republic',
value: 'DE'
},
{
label: 'Italy',
description: 'The Boot',
value: 'IT'
},
{
label: 'Spain',
description: 'The Bull Skin',
value: 'ES'
}
])
</script>
<template>
<B24Listbox :items="items" />
</template>
В пропс items можно передать и массив массивов, чтобы показать группы элементов, разделённые между собой.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[][]>([
[
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
}
],
[
{
label: 'Brazil',
value: 'BR'
},
{
label: 'Argentina',
value: 'AR'
}
]
])
</script>
<template>
<B24Listbox :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[][]>([
[
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
}
],
[
{
label: 'Brazil',
value: 'BR'
},
{
label: 'Argentina',
value: 'AR'
}
]
])
</script>
<template>
<B24Listbox :items="items" />
</template>
Множественный выбор
Пропс multiple разрешает выбрать несколько элементов. Тогда v-model становится массивом.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
</script>
<template>
<B24Listbox multiple :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
</script>
<template>
<B24Listbox multiple :items="items" />
</template>
Ключ значения
Пропс value-key позволяет привязать одно свойство объекта вместо всего объекта. По умолчанию undefined.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
const value = ref('FR')
</script>
<template>
<B24Listbox v-model="value" value-key="value" :items="items" class="w-full" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
const value = ref('FR')
</script>
<template>
<B24Listbox v-model="value" value-key="value" :items="items" class="w-full" />
</template>
Фильтр
Пропс filter показывает поле фильтра или принимает объект для настройки компонента Input. По умолчанию false.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
},
{
label: 'Netherlands',
value: 'NL'
},
{
label: 'Poland',
value: 'PL'
}
])
</script>
<template>
<B24Listbox :filter="{
placeholder: 'Фильтр...'
}" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
},
{
label: 'Netherlands',
value: 'NL'
},
{
label: 'Poland',
value: 'PL'
}
])
</script>
<template>
<B24Listbox :filter="{
placeholder: 'Фильтр...'
}" :items="items" />
</template>
Иконка выбранного элемента
Пропс selected-icon меняет иконку выбранного элемента.
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
const value = ref('FR')
</script>
<template>
<B24Listbox v-model="value" :selected-icon="RocketIcon" value-key="value" :items="items" class="w-full" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
const value = ref('FR')
</script>
<template>
<B24Listbox v-model="value" :selected-icon="RocketIcon" value-key="value" :items="items" class="w-full" />
</template>
Размер
Пропс size меняет размер Listbox.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
</script>
<template>
<B24Listbox size="xl" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
</script>
<template>
<B24Listbox size="xl" :items="items" />
</template>
Загрузка
Пропс loading показывает индикатор загрузки, а пропс loading-icon меняет его иконку.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
}
])
</script>
<template>
<B24Listbox loading :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
}
])
</script>
<template>
<B24Listbox loading :items="items" />
</template>
Отключение
Пропс disabled блокирует любое взаимодействие пользователя с Listbox.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
</script>
<template>
<B24Listbox disabled :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
value: 'FR'
},
{
label: 'Germany',
value: 'DE'
},
{
label: 'Italy',
value: 'IT'
},
{
label: 'Spain',
value: 'ES'
}
])
</script>
<template>
<B24Listbox disabled :items="items" />
</template>
Примеры
С типом элемента
Свойство type со значением separator показывает разделитель между элементами, а со значением label — подпись.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[][]>([
[
{
type: 'label',
label: 'Fruits'
},
{
label: 'Apple'
},
{
label: 'Banana'
},
{
label: 'Blueberry'
},
{
label: 'Grapes'
},
{
label: 'Pineapple'
}
],
[
{
type: 'label',
label: 'Vegetables'
},
{
label: 'Aubergine'
},
{
label: 'Broccoli'
},
{
label: 'Carrot'
},
{
label: 'Courgette'
},
{
label: 'Leek'
}
]
])
</script>
<template>
<B24Listbox :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[][]>([
[
{
type: 'label',
label: 'Fruits'
},
{
label: 'Apple'
},
{
label: 'Banana'
},
{
label: 'Blueberry'
},
{
label: 'Grapes'
},
{
label: 'Pineapple'
}
],
[
{
type: 'label',
label: 'Vegetables'
},
{
label: 'Aubergine'
},
{
label: 'Broccoli'
},
{
label: 'Carrot'
},
{
label: 'Courgette'
},
{
label: 'Leek'
}
]
])
</script>
<template>
<B24Listbox :items="items" />
</template>
label используется как заголовок группы, передайте массив массивов: тогда при поиске подпись исчезает вместе со своей группой.С иконкой в элементах
Свойство icon показывает иконку внутри элементов.
С аватаром в элементах
Свойство avatar показывает Avatar внутри элементов.
С чипом в элементах
Свойство chip показывает Chip внутри элементов.
С описанием в элементах
Свойство description показывает дополнительный текст под подписью.
<script setup lang="ts">
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
description: 'The Hexagon',
value: 'FR'
},
{
label: 'Germany',
description: 'The Federal Republic',
value: 'DE'
},
{
label: 'Italy',
description: 'The Boot',
value: 'IT'
},
{
label: 'Spain',
description: 'The Bull Skin',
value: 'ES'
}
])
</script>
<template>
<B24Listbox :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ListboxItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ListboxItem[]>([
{
label: 'France',
description: 'The Hexagon',
value: 'FR'
},
{
label: 'Germany',
description: 'The Federal Republic',
value: 'DE'
},
{
label: 'Italy',
description: 'The Boot',
value: 'IT'
},
{
label: 'Spain',
description: 'The Bull Skin',
value: 'ES'
}
])
</script>
<template>
<B24Listbox :items="items" />
</template>
Управление выбранными элементами
Выбранным элементом управляют пропс default-value или директива v-model.
Управление поисковым запросом
Директива v-model:search-term управляет поисковым запросом.
С отключённым фильтром
Пропс ignore-filter со значением true отключает внутренний поиск, и вы можете использовать собственную логику поиска.
refDebounced.С полями фильтрации
Пропс filter-fields принимает массив полей, по которым выполняется фильтрация. По умолчанию [labelKey].
С виртуализацией
Пропс virtualize включает виртуализацию для больших списков: булево значение или объект с параметрами вроде { estimateSize: 32, overscan: 12 }.
Как список переноса
Два компонента Listbox с кнопками Button позволяют собрать шаблон списка переноса.
API
Пропсы
Слоты
События
Тема
export default {
slots: {
root: 'flex flex-col min-h-0 min-w-0 ring ring-inset ring-(--ui-color-design-outline-stroke) rounded-lg overflow-hidden outline-(--b24ui-border-color) has-focus-visible:outline-3 has-focus-visible:ring-(--b24ui-border-color)',
input: 'border-b border-(--ui-color-design-outline-stroke) has-focus-visible:border-(--b24ui-border-color)',
content: 'relative overflow-y-auto flex-1 max-h-60 scroll-py-1 focus:outline-none',
group: 'isolate',
label: 'w-full min-w-[195px] h-(--popup-window-delimiter-section-height) px-4.5 mt-(--menu-item-block-stack-space) flex flex-row rtl:flex-row-reverse items-center select-none outline-none whitespace-nowrap text-start text-(length:--ui-size-sm) text-legend font-(--ui-font-weight-normal) after:ms-[10px] after:block after:flex-1 after:min-w-[15px] after:h-px after:bg-(--ui-color-divider-vibrant-default)',
separator: 'my-2 mx-4.5 h-[1px] bg-(--ui-color-divider-vibrant-default)',
empty: 'py-2 select-none outline-none whitespace-nowrap text-center text-(length:--popup-window-delimiter-font-size)/(--ui-font-line-height-lg) text-legend font-(--ui-font-weight-normal)',
loading: 'flex items-center justify-center text-muted',
loadingIcon: 'shrink-0',
item: 'group relative w-full flex items-start select-none outline-none before:absolute before:z-[-1] before:inset-0 data-disabled:cursor-not-allowed data-disabled:opacity-75 text-default data-highlighted:not-data-disabled:text-label data-[state=checked]:text-label data-highlighted:not-data-disabled:before:bg-(--ui-color-base-black-fixed)/3 dark:data-highlighted:not-data-disabled:before:bg-(--ui-color-base-black-fixed) transition-colors before:transition-colors',
itemLeadingIcon: 'size-[25px] shrink-0 text-(--ui-color-base-5)',
itemLeadingAvatar: 'shrink-0',
itemLeadingAvatarSize: '',
itemLeadingChip: 'shrink-0',
itemLeadingChipSize: '',
itemWrapper: 'flex-1 flex flex-col min-w-0',
itemLabel: 'truncate',
itemDescription: 'truncate -mt-[6px] text-description text-(length:--ui-font-size-sm)',
itemTrailing: 'ml-auto rtl:ml-0 rtl:mr-auto inline-flex gap-1.5 items-center',
itemTrailingIcon: 'shrink-0 text-(--ui-color-accent-main-primary)'
},
variants: {
size: {
xss: {
label: 'p-1 text-[10px]/3 gap-1',
empty: 'py-3 text-[10px]',
loading: 'py-3',
loadingIcon: 'size-2',
item: 'p-1 text-[10px] gap-1',
itemLeadingIcon: 'size-3 mt-0.5',
itemLeadingAvatar: 'size-3 mt-0.5',
itemLeadingAvatarSize: '3xs',
itemLeadingChip: 'size-3 mt-0.5',
itemLeadingChipSize: '2xs',
itemTrailingIcon: 'size-3 mt-0.5'
},
xs: {
label: 'p-1 text-[10px]/3 gap-1',
empty: 'py-3 text-[12px]',
loading: 'py-3',
loadingIcon: 'size-[12px]',
item: 'p-1 text-[12px] gap-1',
itemLeadingIcon: 'size-4 mt-0.5',
itemLeadingAvatar: 'size-4 mt-0.5',
itemLeadingAvatarSize: '3xs',
itemLeadingChip: 'size-3 mt-0.5',
itemLeadingChipSize: 'sm',
itemTrailingIcon: 'size-4 mt-0.5'
},
sm: {
label: 'p-1.5 text-[10px]/3 gap-1.5',
empty: 'py-4 text-[14px]',
loading: 'py-4',
loadingIcon: 'size-4',
item: 'p-1.5 text-[14px] gap-1.5',
itemLeadingIcon: 'size-5',
itemLeadingAvatar: 'size-5',
itemLeadingAvatarSize: '3xs',
itemLeadingChip: 'size-4 mt-1',
itemLeadingChipSize: 'sm',
itemTrailingIcon: 'size-5'
},
md: {
label: 'px-4.5 py-1.5 text-xs gap-1.5',
empty: 'py-6 text-(length:--ui-font-size-xl)',
loading: 'py-6',
loadingIcon: 'size-6',
item: 'px-4.5 py-1.5 text-(length:--ui-font-size-xl) gap-1.5',
itemLeadingIcon: 'size-6',
itemLeadingAvatar: 'size-6',
itemLeadingAvatarSize: '2xs',
itemLeadingChip: 'size-5 mt-1',
itemLeadingChipSize: 'md',
itemTrailingIcon: 'size-6'
},
lg: {
label: 'p-2 text-xs gap-2',
empty: 'py-7 text-(length:--ui-font-size-xl)',
loading: 'py-7',
loadingIcon: 'size-8',
item: 'p-2 text-(length:--ui-font-size-xl) gap-2',
itemLeadingIcon: 'size-7',
itemLeadingAvatar: 'size-7',
itemLeadingAvatarSize: '2xs',
itemLeadingChip: 'size-5 mt-1',
itemLeadingChipSize: 'md',
itemTrailingIcon: 'size-6'
},
xl: {
label: 'p-2 text-(length:--ui-font-size-xl) gap-2',
empty: 'py-8 text-(length:--ui-font-size-4xl)',
loading: 'py-8',
loadingIcon: 'size-10',
item: 'p-2 text-(length:--ui-font-size-4xl) gap-2',
itemLeadingIcon: 'size-7',
itemLeadingAvatar: 'size-7',
itemLeadingAvatarSize: 'xs',
itemLeadingChip: 'size-6',
itemLeadingChipSize: 'lg',
itemTrailingIcon: 'size-6',
itemDescription: 'text-(length:--ui-font-size-xl)'
}
},
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'
}
},
virtualize: {
true: {
content: 'p-1 isolate'
},
false: {
content: 'divide-y divide-(--ui-color-divider-default)'
}
},
disabled: {
true: {
root: 'cursor-not-allowed opacity-30'
}
},
highlight: {
true: 'ring ring-inset ring-(--b24ui-border-color)'
}
},
defaultVariants: {
color: 'air-primary',
size: 'md'
}
}