以字符串数组管理一组独立选项。每个选项提供唯一且非空的 value 和可读 label,可补充 description、disabled。
基础用法
v-model 管理选中值数组;defaultValue 设置非受控初始值。label 说明整组用途,默认纵向排列。
全选组合
通过 before 插槽组合全选按钮。上下文提供 allChecked、allDisabled、readOnly、size 和 toggleAll,可直接绑定到 Checkbox。
全选只改变可用选项。取消全选时,禁用项及当前未呈现的已有值仍保留在模型中。
尺寸与方向
size 支持 xs 至 xl,默认 sm;orientation="horizontal" 横向排列,空间不足时换行。外层 Field 已有标签时可设置 hideLabel,同时保留组的可访问名称。
只读、禁用与错误
readOnly 禁止修改并保留焦点与值;disabled 禁止交互和原生提交。invalid 展示外部校验结果,单项 disabled 只锁定对应选项。
表单与必填
数组必填由 QuireFormField 校验;不要给每个 Checkbox 都加 required,否则会要求全部选中。将字段值收窄为字符串数组,再通过公开 controlProps 传递状态与事件。
直接使用原生表单时,选中且启用的条目以相同 name 重复提交,读取时使用 FormData.getAll(name)。模型中的未知值没有对应字段,不参与原生提交;受控模型的重置由宿主或 Form 管理。
键盘操作
| 按键 | 行为 |
|---|---|
Tab | 依次聚焦可用复选项,包括全选。 |
Space | 切换当前项;只读时保留原值。 |
API
QuireCheckboxGroup Props
Slots 内容位置
beforeCompose a select-all checkbox or explanatory content before the options.
{ /** Current host or local selection. */ value: readonly (string)[]; /** State derived from enabled items only. */ allChecked: false | true | "indeterminate"; /** Whether there are no enabled items or the whole group is disabled. */ allDisabled: boolean; /** Read-only state for controls composed by the host. */ readOnly: boolean; /** Shared size for composed controls. */ size: "xs" | "sm" | "md" | "lg" | "xl"; /** Toggle all enabled options while preserving other stored values. */ toggleAll: { (): void; }; }afterContent after all options.
{ /** Current host or local selection. */ value: readonly (string)[]; /** State derived from enabled items only. */ allChecked: false | true | "indeterminate"; /** Whether there are no enabled items or the whole group is disabled. */ allDisabled: boolean; /** Read-only state for controls composed by the host. */ readOnly: boolean; /** Shared size for composed controls. */ size: "xs" | "sm" | "md" | "lg" | "xl"; /** Toggle all enabled options while preserving other stored values. */ toggleAll: { (): void; }; }itemReplace an item's label, retaining its native checkbox control.
{ item: { /** Stable unique value submitted with the group name. */ value: string; /** Readable option name. */ label: string; /** Optional supporting text. */ description?: undefined | string; /** Preserve the stored value but disallow changes and submission. */ disabled?: boolean | undefined; }; checked: boolean; }
Events 组件事件
update:modelValue更新
modelValue,可通过对应 v-model 绑定。[value: string[]]