Skip to content

Checkbox

A group of options for multiple selections.

Basic Usage

The v-model attribute is used to set the currently selected value.

html
<wd-checkbox v-model="value">Option</wd-checkbox>
typescript
import { reactive, toRefs } from 'vue'

export default {
  setup() {
    const state = reactive({
      value: true
    })

    return {
      ...toRefs(state)
    }
  }
}

Disabled State

Set the disabled attribute to disable the checkbox.

html
<wd-checkbox v-model="value" disabled>Disabled Option</wd-checkbox>

Custom Shape

Set the shape attribute to customize the shape of the checkbox, which can be set to 'button' or 'square', default is 'circle'.

html
<wd-checkbox v-model="value1" shape="square">Square Checkbox</wd-checkbox>
<wd-checkbox v-model="value2" shape="button">Button Checkbox</wd-checkbox>

Custom Color

Set the checked-color attribute to customize the color when checked.

html
<wd-checkbox v-model="value" checked-color="#4D80F0">Custom Color</wd-checkbox>

Checkbox Size

Set the size attribute to customize the size of the checkbox, which can be set to 'large', default is ''.

html
<wd-checkbox v-model="value" size="large">Large Checkbox</wd-checkbox>

True Value and False Value

Set the true-value and false-value attributes to customize the value when checked and unchecked.

html
<wd-checkbox v-model="value" true-value="yes" false-value="no">Custom Value</wd-checkbox>

Checkbox Group

The value of the checkbox group is an array, which contains the values of all selected checkboxes. The value of each checkbox is set through the value attribute.

html
<wd-checkbox-group v-model="value">
  <wd-checkbox value="1">Option 1</wd-checkbox>
  <wd-checkbox value="2">Option 2</wd-checkbox>
  <wd-checkbox value="3">Option 3</wd-checkbox>
  <wd-checkbox value="4">Option 4</wd-checkbox>
</wd-checkbox-group>
typescript
import { reactive, toRefs } from 'vue'

export default {
  setup() {
    const state = reactive({
      value: ['1', '3']
    })

    return {
      ...toRefs(state)
    }
  }
}

Horizontal Display

Set the inline attribute to display checkboxes horizontally.

html
<wd-checkbox-group v-model="value" inline>
  <wd-checkbox value="1">Option 1</wd-checkbox>
  <wd-checkbox value="2">Option 2</wd-checkbox>
  <wd-checkbox value="3">Option 3</wd-checkbox>
  <wd-checkbox value="4">Option 4</wd-checkbox>
</wd-checkbox-group>

Disabled Checkbox Group

Set the disabled attribute on the checkbox group to disable all checkboxes in the group.

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

Custom Shape for Checkbox Group

Set the shape attribute on the checkbox group to customize the shape of all checkboxes in the group.

html
<wd-checkbox-group v-model="value" shape="square">
  <wd-checkbox value="1">Option 1</wd-checkbox>
  <wd-checkbox value="2">Option 2</wd-checkbox>
  <wd-checkbox value="3">Option 3</wd-checkbox>
  <wd-checkbox value="4">Option 4</wd-checkbox>
</wd-checkbox-group>

Custom Color for Checkbox Group

Set the checked-color attribute on the checkbox group to customize the color of all checkboxes in the group when checked.

html
<wd-checkbox-group v-model="value" checked-color="#4D80F0">
  <wd-checkbox value="1">Option 1</wd-checkbox>
  <wd-checkbox value="2">Option 2</wd-checkbox>
  <wd-checkbox value="3">Option 3</wd-checkbox>
  <wd-checkbox value="4">Option 4</wd-checkbox>
</wd-checkbox-group>

Custom Size for Checkbox Group

Set the size attribute on the checkbox group to customize the size of all checkboxes in the group.

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

Maximum Number of Selections

Set the max attribute on the checkbox group to limit the maximum number of selections.

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

Cell Style

Set the cell attribute on the checkbox group to display checkboxes in cell style.

html
<wd-checkbox-group v-model="value" cell>
  <wd-checkbox value="1">Option 1</wd-checkbox>
  <wd-checkbox value="2">Option 2</wd-checkbox>
  <wd-checkbox value="3">Option 3</wd-checkbox>
  <wd-checkbox value="4">Option 4</wd-checkbox>
</wd-checkbox-group>

Checkbox Attributes

AttributeDescriptionTypeDefaultVersion
v-modelSelected valueboolean / string / number--
valueCheckbox valuestring / number / boolean--
shapeCheckbox shape, can be 'circle', 'square', 'button'stringcircle-
checked-colorColor when checkedstring#4D80F0-
disabledWhether to disable the checkboxbooleanfalse-
true-valueValue when checkedstring / number / booleantrue-
false-valueValue when uncheckedstring / number / booleanfalse-
sizeCheckbox size, can be 'large'string--

Checkbox Events

Event NameDescriptionParametersVersion
changeTriggered when the binding value changesvalue: selected value-

Checkbox Slots

NameDescriptionVersion
defaultCustom content-

Checkbox External Style Classes

Class NameDescriptionVersion
custom-classRoot node custom class-

CheckboxGroup Attributes

AttributeDescriptionTypeDefaultVersion
v-modelSelected valuearray--
shapeCheckbox shape, can be 'circle', 'square', 'button'stringcircle-
checked-colorColor when checkedstring#4D80F0-
disabledWhether to disable all checkboxesbooleanfalse-
maxMaximum number of selectionsnumber--
inlineWhether to display checkboxes horizontallybooleanfalse-
cellWhether to display checkboxes in cell stylebooleanfalse-
sizeCheckbox size, can be 'large'string--

CheckboxGroup Events

Event NameDescriptionParametersVersion
changeTriggered when the binding value changesvalue: selected value-

CheckboxGroup Slots

NameDescriptionVersion
defaultCustom content-

CheckboxGroup External Style Classes

Class NameDescriptionVersion
custom-classRoot node custom class-

Source Code

Documentation
Component

Released under the MIT License.

Ask me