Skip to content

Checkbox

Used to select multiple options from a set of candidates. Supports regular style, button style, custom icons, and select-all control.

Component Type

Basic Usage

html
<wd-checkbox-group v-model="value">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
  <wd-checkbox :name="3" type="square">Option 3</wd-checkbox>
  <wd-checkbox :name="4" type="dot">Option 4</wd-checkbox>
</wd-checkbox-group>

Standalone Usage

wd-checkbox can be used independently without wd-checkbox-group. Use v-model to bind checked state (default true-value is true, false-value is false). You can also customize checked and unchecked values with true-value / false-value.

html
<wd-checkbox v-model="checked">Agree to terms</wd-checkbox>
ts
const checked = ref(false)

Custom Checked/Unchecked Value

html
<wd-checkbox v-model="agree" true-value="yes" false-value="no">Agree to terms</wd-checkbox>
ts
const agree = ref('no')

Component State

Disabled

html
<wd-checkbox-group v-model="value" disabled>
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
</wd-checkbox-group>

<wd-checkbox-group v-model="value">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2" disabled>Option 2</wd-checkbox>
</wd-checkbox-group>

Indeterminate State

html
<wd-checkbox v-model="checked" :indeterminate="indeterminate" @change="indeterminate = false">Indeterminate</wd-checkbox>

Readonly

html
<wd-checkbox-group v-model="value" readonly>
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
</wd-checkbox-group>

Component Variant

Right-side Check Icon

html
<wd-checkbox-group v-model="value" placement="right">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
</wd-checkbox-group>

Button Style

html
<wd-checkbox-group v-model="value" type="button">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
</wd-checkbox-group>

Horizontal Layout

html
<wd-checkbox-group v-model="value" direction="horizontal">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
</wd-checkbox-group>

Minimum and Maximum Selection Count

html
<wd-checkbox-group v-model="value" :min="1" :max="3">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
  <wd-checkbox :name="3">Option 3</wd-checkbox>
  <wd-checkbox :name="4">Option 4</wd-checkbox>
</wd-checkbox-group>

Component Style

Custom Checked Color

html
<wd-checkbox-group v-model="value" checked-color="#fa4350">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
</wd-checkbox-group>

Custom Unchecked Color

html
<wd-checkbox-group v-model="value" unchecked-color="#fa4350">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
</wd-checkbox-group>

Custom Icon

html
<wd-checkbox-group v-model="value">
  <wd-checkbox :name="1">
    Custom Icon
    <template #icon="{ isChecked }">
      <wd-icon :name="isChecked ? 'star-fill' : 'star'" size="22px" :color="isChecked ? '#fa4350' : '#ccc'" />
    </template>
  </wd-checkbox>
</wd-checkbox-group>

Size

html
<wd-checkbox-group v-model="value" size="large">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
</wd-checkbox-group>

Special Style

With Cell

html
<wd-checkbox-group v-model="value" direction="horizontal">
  <wd-cell-group border value-align="right">
    <wd-cell title="Like" clickable @click="toggle(1)">
      <wd-checkbox :name="1" />
    </wd-cell>
    <wd-cell title="Coin" clickable @click="toggle(2)">
      <wd-checkbox :name="2" />
    </wd-cell>
    <wd-cell title="One-click Triple" clickable @click="toggle(3)">
      <wd-checkbox :name="3" />
    </wd-cell>
  </wd-cell-group>
</wd-checkbox-group>

Toggle All

html
<wd-button @click="checkboxGroup?.toggleAll()">Toggle All</wd-button>
<wd-button @click="checkboxGroup?.toggleAll(true)">Select All</wd-button>
<wd-button @click="checkboxGroup?.toggleAll(false)">Unselect All</wd-button>
<wd-button @click="checkboxGroup?.toggleAll({ skipDisabled: true })">Toggle All (Skip Disabled)</wd-button>
<wd-button @click="checkboxGroup?.toggleAll({ checked: true, skipDisabled: true })">Select All (Skip Disabled)</wd-button>

<wd-checkbox-group v-model="value" ref="checkboxGroup">
  <wd-checkbox :name="1">Option 1</wd-checkbox>
  <wd-checkbox :name="2">Option 2</wd-checkbox>
  <wd-checkbox :name="3" disabled>Option 3</wd-checkbox>
  <wd-checkbox :name="4">Option 4</wd-checkbox>
</wd-checkbox-group>

Checkbox Attributes

ParameterDescriptionTypeDefault
v-modelBound value when used standalonestring | number | booleanfalse
nameUnique identifier value in CheckboxGroupstring | number | boolean''
typeShape type, supports circle / square / button / dotstringinherited from CheckboxGroup
checked-colorChecked colorstringinherited from CheckboxGroup
unchecked-colorUnchecked colorstringinherited from CheckboxGroup
disabledWhether disabledboolean | nullinherited from CheckboxGroup
readonlyWhether readonlyboolean | nullinherited from CheckboxGroup
indeterminateWhether indeterminate (highest style priority)booleanfalse
true-valueChecked value when used standalonestring | number | booleantrue
false-valueUnchecked value when used standalonestring | number | booleanfalse
sizeSize, supports largestringinherited from CheckboxGroup
placementCheck icon position, supports left / rightstringinherited from CheckboxGroup
directionLayout direction, supports horizontal / verticalstringinherited from CheckboxGroup
max-widthMaximum text widthstring-
custom-label-classCustom class for label textstring-
custom-classCustom class for root nodestring''
custom-styleCustom style for root nodestring''

CheckboxGroup Attributes

ParameterDescriptionTypeDefault
v-modelBound value arrayArray<string | number | boolean>[]
typeShape type, supports circle / square / button / dotstringcircle
checked-colorChecked colorstring-
unchecked-colorUnchecked colorstring-
disabledWhether all options are disabledbooleanfalse
readonlyWhether all options are readonlybooleanfalse
minMinimum selectable countnumber0
maxMaximum selectable count, 0 means no limitnumber0
sizeSize, supports largestring-
placementCheck icon position, supports left / rightstringleft
directionLayout direction, supports horizontal / verticalstringvertical
custom-classCustom class for root nodestring''
custom-styleCustom style for root nodestring''

Checkbox Events

Event NameDescriptionParameters
changeTriggered when bound value changes in standalone usage{ value }

CheckboxGroup Events

Event NameDescriptionParameters
changeTriggered when group selected value changes{ value }

Checkbox Methods

Method NameDescriptionParameters
toggleToggle current checked state-

CheckboxGroup Methods

Method NameDescriptionParameters
toggleAllBatch toggle all optionsboolean | { checked?: boolean; skipDisabled?: boolean }

Checkbox Slots

nameDescriptionParameters
defaultCustom label content-
iconCustom icon{ isChecked }

CheckboxGroup Slots

nameDescriptionParameters
defaultCheckbox list content-

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-checkbox-label-margin$spacing-tight-
--wot-checkbox-color-checked$primary-6文字与图标距离
--wot-checkbox-icon-size$n-22选中颜色
--wot-checkbox-unchecked-color$coolgrey-3图标尺寸
--wot-checkbox-label-font-size$typography-body-size-main未选中图标颜色
--wot-checkbox-label-color$text-main文字字号
--wot-checkbox-label-line-height$typography-body-line-height-size-main文字颜色
--wot-checkbox-opacity-disabled$opacity-disabled文字行高
--wot-checkbox-horizontal-margin$spacing-zero $spacing-extra-loose $spacing-zero $spacing-zero禁用态透明度
--wot-checkbox-button-margin$spacing-zero $spacing-extra-loose $spacing-extra-loose $spacing-zero水平模式多个单选框距离
--wot-checkbox-button-border-width$stroke-main按钮模式多个单选框距离
--wot-checkbox-button-shape-border-radius$radius-full边框宽度
--wot-checkbox-button-shape-size$n-26按钮模式图标圆角大小
--wot-checkbox-button-font-size$typography-body-size-main按钮模式图标容器大小
--wot-checkbox-button-line-height$typography-body-line-height-size-main按钮模式字号
--wot-checkbox-button-bg$filled-bottom按钮模式行高
--wot-checkbox-button-bg-checked$filled-oppo按钮模式背景颜色
--wot-checkbox-button-icon-size$n-10按钮模式选中状态背景颜色
--wot-checkbox-button-min-widthcalc(74 * #{$n-1})按钮模式图标尺寸
--wot-checkbox-button-max-widthcalc(148 * #{$n-1})按钮模式最小宽
--wot-checkbox-button-border-radius$radius-main按钮模式最大宽
--wot-checkbox-button-padding$padding-extra-tight $padding-extra-loose按钮圆角大小
--wot-checkbox-button-icon-color$icon-white按钮模式内边距
--wot-checkbox-button-shape-topcalc(-1 * #{$n-11})按钮模式图标颜色
--wot-checkbox-button-shape-leftcalc(-1 * #{$n-9})按钮模式勾角顶部偏移
--wot-checkbox-button-shape-rightcalc(-1 * #{$n-9})按钮模式勾角左侧偏移
--wot-checkbox-button-icon-topcalc(13 * #{$n-1})按钮模式勾角右侧偏移
--wot-checkbox-button-icon-right$n-4按钮模式图标顶部偏移
--wot-checkbox-button-icon-left$n-4按钮模式图标右侧偏移

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.