组件
列表框 Listbox
Listbox:列表框。行内容保持低调,只有选中行使用 primary 平铺填充。部件:Root、Label、Input、Content、Empty、Item、ItemText、ItemIndicator、ItemGroup、ItemGroupLabel、ValueText;collection 位于共享 collection 模块。
#基础用法
Accent
Qinghua cobalt
Celadon
Zhusha cinnabar
Ochre
<script setup lang="ts">
import { Listbox, createListCollection } from "@bysages/vue";
const pigments = createListCollection({
items: [
{ label: "Qinghua cobalt", value: "qinghua" },
{ label: "Celadon", value: "celadon" },
{ label: "Zhusha cinnabar", value: "zhusha" },
{ label: "Ochre", value: "ochre" },
],
});
</script>
<template>
<Listbox.Root :collection="pigments" selection-mode="single">
<Listbox.Label>Accent</Listbox.Label>
<Listbox.Content>
<Listbox.Item v-for="item in pigments.items" :key="item.value" :item="item">
<Listbox.ItemText>{{ item.label }}</Listbox.ItemText>
<Listbox.ItemIndicator>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path
d="M4 8.5l2.5 2.5L12 5.5"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</Listbox.ItemIndicator>
</Listbox.Item>
</Listbox.Content>
</Listbox.Root>
</template>
#属性
#Content
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Empty
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Input
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
autoHighlight | boolean | undefined | false | 输入时是否自动高亮选项 |
keyboardPriority | "caret" | "navigate" | undefined | "caret" | 输入框键盘事件的优先级:caret 保留原生文本编辑行为,navigate 把支持的按键转发给列表框导航 |
#ItemContext
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#ItemGroupLabel
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#ItemGroup
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#ItemIndicator
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#ItemText
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Item
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
highlightOnHover | boolean | undefined | 悬停时是否高亮选项 | |
item | T | 要渲染的列表选项 |
#Label
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#Root
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
size | String as PropType<"sm" | "md" | "lg"> | "md" | 行和筛选字段使用的尺寸档位 |
collection | ListCollection<T> | 选项集合 | |
defaultHighlightedValue | string | 打开时默认高亮项的值;适合不需要受控高亮值的场景 | |
defaultValue | string[] | [] | 列表框的初始默认值;适合不需要受控值的场景 |
deselectable | boolean | 是否禁止空选择 | |
disabled | boolean | 是否禁用列表框 | |
disallowSelectAll | boolean | 按下 meta+a 时是否禁止全选 | |
highlightedValue | string | 高亮项的受控值 | |
id | string | 组件内部状态机的唯一标识 | |
ids | Partial<{ root: string; content: string; label: string; item(id: string | number): string; itemGroup(id: string | number): string; itemGroupLabel(id: string | number): string; }> | 列表框各元素的 id,便于组合使用 | |
loopFocus | boolean | false | 键盘导航是否在选项间循环 |
modelValue | string[] | 列表框的模型值 | |
orientation | 'horizontal' | 'vertical' | "horizontal" | 列表框的排列方向 |
scrollToIndexFn | (details: listbox.ScrollToIndexDetails) => void | 滚动到指定索引的函数 | |
selectionMode | listbox.SelectionMode | "single" | 列表框的选择行为:single 只能选择一个选项,multiple 不按修饰键也能选择多个,extended 需要配合修饰键选择多个 |
selectOnHighlight | boolean | 选项高亮时是否选中 | |
typeahead | boolean | 是否启用输入即查找 |
#ValueText
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
placeholder | string | — |