CheckboxGroup Checkbox group
Manage multiple selections, option data and selection limits.
Import
Use <hui-checkbox-group> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
<template>
<view>
<hui-checkbox-group
ref="control"
v-model="selected"
:options="options"
:min="1"
:max="2"
@update:model-value="event0"
@change="event1"
@limit-reach="event2"
/>
<text>{{ selected }}</text
><hui-button @click="control?.toggleAll(true)">全选 / Select all</hui-button>
<hui-button @click="() => control?.toggleAll()">toggleAll()</hui-button>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const control = ref()
const selected = ref<Array<string | number | boolean>>(['a'])
const options = [
{ label: '选项 A / Option A', value: 'a' },
{ label: '选项 B / Option B', value: 'b' },
{ label: '禁用 / Disabled', value: 'c', disabled: true }
]
const event0 = (arg0: unknown) => {
lastEvent.value = 'update:modelValue' + ': ' + [describe(arg0)].join(', ')
}
const event1 = (arg0: unknown, arg1: unknown) => {
lastEvent.value = 'change' + ': ' + [describe(arg0), describe(arg1)].join(', ')
}
const event2 = (arg0: unknown) => {
lastEvent.value = 'limit-reach' + ': ' + [describe(arg0)].join(', ')
}
</script>
The options source takes precedence over the default slot. Reaching min/max emits limit-reach; controlled values still require parent updates.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | ChoiceValue[] | — | Controlled value; undefined means omitted. |
defaultValue | ChoiceValue[] | [] | Initial uncontrolled value; ignored in controlled mode. |
options | Record<string, unknown>[] | — | Option data; takes precedence over the default slot. |
props | { label?: string | undefined; value?: string | undefined; disabled?: string | undefined; } | — | Data field-name mapping. |
min | number | — | Minimum selection count or numeric value. |
max | number | — | Maximum selection count, numeric value or displayed count. |
direction | "vertical" | "horizontal" | 'horizontal' | Layout direction. |
disabled | boolean | false | Disable interaction. |
readonly | boolean | undefined | Read-only presentation without value changes. |
size | ComponentSize | — | Component size; inherits configuration when omitted. |
shape | "round" | "square" | — | Selection indicator shape. |
iconPosition | "left" | "right" | — | Icon position relative to the label. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: ChoiceValue[]) | Request a controlled value update. |
change | (value: ChoiceValue[], ctx: { option?: Record<string, unknown>; checked: boolean }) | Emitted after the value changes. |
limit-reach | (limit: 'min' | 'max') | Minimum or maximum selection limit reached. |
Slots
| Slot | Parameters | Description |
|---|---|---|
option | { option, checked, disabled } | Custom option region; replaces its fallback content. |
default | — | Main content. |
Methods
| Method | Signature | Description |
|---|---|---|
toggleAll | (checked?: boolean | undefined): void | Toggle enabled options within selection limits. |
Types
CheckboxGroupProps、CheckboxGroupExpose、CheckboxGroupEmits are available from @nscode/handy-uni.
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.