组件
切换按钮组 Toggle Group
ToggleGroup:切换按钮组。发丝线托盘中,按下的项使用墨色平铺填充。部件:Root、Item。
#基础用法
<script setup lang="ts">
import { ToggleGroup } from "@bysages/vue";
const strokeAttrs = {
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
"stroke-width": "2",
"stroke-linecap": "round",
"stroke-linejoin": "round",
"aria-hidden": "true",
};
const aligns = [
{ value: "left", label: "Align left", d: "M4 4v16M9 8h10M9 12h12M9 16h7" },
{ value: "center", label: "Align center", d: "M12 4v16M7 8h10M4 12h16M8 16h8" },
{ value: "right", label: "Align right", d: "M20 4v16M5 8h10M3 12h12M8 16h7" },
{ value: "justify", label: "Align justified", d: "M4 6h16M4 12h16M4 18h16" },
];
</script>
<template>
<ToggleGroup.Root :default-value="['left']" aria-label="Text alignment">
<ToggleGroup.Item
v-for="align in aligns"
:key="align.value"
:value="align.value"
:aria-label="align.label"
>
<svg v-bind="strokeAttrs"><path :d="align.d" /></svg>
</ToggleGroup.Item>
</ToggleGroup.Root>
</template>
#属性
#Item
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
disabled | boolean | undefined | — | |
value | string | — |
#Root
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
size | String as PropType<"sm" | "md" | "lg"> | "md" | 切换项的高度档位 |
defaultValue | string[] | toggle group 渲染时的初始选中值;不需要控制选中值时使用 | |
deselectable | boolean | true | toggle group 是否允许不选中任何项;multiple 为 true 时忽略 |
disabled | boolean | toggle 是否禁用 | |
id | string | 组件内部状态机的唯一标识 | |
ids | Partial<{ root: string; item(value: string): string; }> | toggle 各元素的 id,适合组合使用 | |
loopFocus | boolean | true | 焦点是否在 toggle group 内循环 |
modelValue | string[] | toggle group 的 v-model 值 | |
multiple | boolean | 是否允许同时选中多个切换项 | |
orientation | toggleGroup.Orientation | "horizontal" | toggle group 的方向 |
rovingFocus | boolean | true | 是否用 roving tab index 管理焦点 |