Skip to content

Checkbox Component ​

The checkbox component is generally used in scenarios where multiple selections are needed. It is fully functional and easy to use.

📌 Platform Compatibility ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage ​

html
<template>
    <!-- Global usage -->
    <hy-checkbox v-model="value" :columns="columns"></hy-checkbox>

    <!-- Separate components -->
    <hy-checkbox-group v-model="value2">
        <hy-checkbox-item value="f" label="Ferrari" :checked="true"></hy-checkbox-item>
        <hy-checkbox-item value="l" label="Lamborghini"></hy-checkbox-item>
        <hy-checkbox-item value="b" label="Bugatti"></hy-checkbox-item>
        <hy-checkbox-item value="a" label="Aston Martin"></hy-checkbox-item>
    </hy-checkbox-group>
</template>

<script lang="ts" setup>
    import { ref } from 'vue';

    const columns = [
        {
            label: 'Apple',
            value: 'apply',
        },
        {
            label: 'Banana',
            value: 'banana',
        },
    ];
    const value = ref(['apply']);
    const value2 = ref(['']);
</script>

Custom columns Keys ​

html
<template>
    <hy-checkbox v-model="value" :columns="columns" :fieldNames="fieldNames"></hy-checkbox>
</template>

<script lang="ts" setup>
    import { ref } from 'vue';

    const columns = [
        {
            name: 'Apple',
            value_1: 'apply',
        },
        {
            name: 'Banana',
            value_1: 'banana',
        },
    ];
    const value = ref([]);
    const fieldNames = ref({
        label: 'name',
        value: 'value_1',
        checked: 'checked',
    });
</script>

Single Item ​

html
<template>
    <hy-checkbox v-model="value" :columns="columns"></hy-checkbox>
</template>

<script setup lang="ts">
    import { ref } from 'vue';
    const value = ref(false);

    const columns = [
        {
            name: 'Remember password',
            value: 1,
        },
    ];
</script>

Custom Shape ​

You can set the checkbox to square or circular by setting shape to square or circle

html
<hy-checkbox v-model="value" :columns="columns" shape="square"></hy-checkbox>
<hy-checkbox v-model="value" :columns="columns" shape="circle"></hy-checkbox>

Custom Color ​

html
<hy-checkbox v-model="value" :columns="columns" activeColor="red"></hy-checkbox>

Arrangement ​

You can arrange the checkboxes horizontally or vertically by setting placement to row or column

html
<hy-checkbox v-model="value" :columns="columns" placement="row"></hy-checkbox>
<hy-checkbox v-model="value" :columns="columns" placement="column"></hy-checkbox>

Horizontal Both-Ends Arrangement ​

You can set the alignment of the checkbox icon to left or right by setting iconPlacement to left or right

html
<hy-checkbox v-model="value" :columns="columns" iconPlacement="right" placement="row"></hy-checkbox>
<hy-checkbox v-model="value" :columns="columns" iconPlacement="left" placement="row"></hy-checkbox>

Disabled ​

html
<template>
    <!-- Disable all -->
    <hy-checkbox v-model="value" :columns="columns" disabled></hy-checkbox>
</template>

<script lang="ts" setup>
    import { ref } from 'vue';

    const columns = [
        {
            label: 'Apple',
            value: 'apply',
            disabled: true, // Disable a single item
        },
        {
            label: 'Banana',
            value: 'banana',
        },
    ];
    const value = ref(['apply']);
</script>

Slots ​

  • label: Custom label text, the passed value is label
  • icon: Custom icon inside the checkbox, the passed values are iconColor and iconSize
html
<template>
    <hy-checkbox v-model="value" :columns="columns">
        <template #label="{ label }">
            <view>{{label}}</view>
        </template>
        <template #icon="{ iconColor, iconSize }">
            <view>{{iconColor}}</view>
            <view>{{iconSize}}</view>
        </template>
    </hy-checkbox>
</template>

<script lang="ts" setup>
    import { ref } from 'vue';

    const columns = [
        {
            label: 'Apple',
            value: 'apply',
        },
        {
            label: 'Banana',
            value: 'banana',
        },
    ];
    const value = ref(['apply']);
</script>

API ​

Checkbox Props ​

ParameterDescriptionTypeDefault
v-modelTwo-way binding value, array type(string|number)[] |boolean-
columnsAccepts an array valuearray-
fieldNamesCustom keys for receiving columnsobject{label: "label",value: "value",checked: "checked"}
shapeCheckbox shape[1]circle|squaresquare
sizeCheckbox size[2]small|medium|large |string|numbermedium
disabledWhether to disablebooleanfalse
activeColorColor in the selected statestring-
inactiveColorColor in the unselected statestring#c8c9cc
iconSizeIcon size, numbers default to pxstring|number20
iconColorIcon colorstring-
labelSizeLabel font size, numbers default to pxstring|number-
labelColorLabel colorstring-
iconPlacementAlignment of the check iconleft|rightleft
borderBottomWhether to show an underline in vertical layoutbooleanfalse
labelDisabledWhether to prevent clicking the label to select the checkboxbooleanfalse
placementLayout[3]row|columnrow
customStyleCustom external styles to be appliedCSSProperties-

CheckboxGroup Props ​

ParameterDescriptionTypeDefault
v-modelTwo-way binding value, array type(string|number)[]|boolean-
shapeCheckbox shape[1:1]circle|squaresquare
sizeCheckbox size[2:1]small|medium|large|string|numbermedium
disabledWhether to disablebooleanfalse
activeColorColor in the selected statestring-
inactiveColorColor in the unselected statestring#c8c9cc
iconSizeIcon size, in pxstring|number20
iconColorIcon colorstring-
labelSizeLabel font size, in pxstring|number-
labelColorLabel colorstring-
iconPlacementAlignment of the check iconleft|rightleft
borderBottomWhether to show an underline in vertical layoutbooleanfalse
labelDisabledWhether to prevent clicking the label to select the checkboxbooleanfalse
placementLayout[3:1]row|columnrow
customStyleCustom external styles to be appliedCSSProperties-

CheckboxItem Props ​

ParameterDescriptionTypeDefault
valueBinding valuestring-
labelLabel textstring-
checkedWhether selected by defaultbooleanfalse
disabledWhether to disablebooleanfalse

columns ​

ParameterDescriptionTypeDefault
labelDisplayed text contentstring-
valueValuestring-
checkedWhether selectedboolean-
disabledWhether to disableboolean-

API ​

ParameterDescriptionTypeDefault
labelCustom text key for columnsstringlabel
valueCustom value key for columnsstringvalue
checkedCustom checked key for columnsstringchecked

CheckboxItem Events ​

Event NameDescriptionCallback Parameters
changeTriggered when any checkbox state changes, the callback is an objectdetail = array( [elements are the values of the selected checkboxes] )

CheckboxItem Slots ​

Slot NameDescriptionPassed Values
iconCustom icon contenticonColor | iconSize
labelCustom label contentrecord

CSS Variables ​

VariableDescriptionDefault
--hy-checkbox-marginOuter margin5px
--hy-checkbox-radius-squareBorder radius of square checkbox3px
--hy-checkbox-disabled-checked-opacityOpacity when disabled and checked0.5
--hy-checkbox-font-sizeLabel font sizeFollows --hy-font-size-base (28rpx)
--hy-checkbox-disabled-colorDisabled text colorFollows --hy-text-color--disabled
--hy-checkbox-borderCheckbox borderFollows --hy-border-line
12:33
battery

  1. circle: both sides are semicircular; square: square with rounded corners ↩︎ ↩︎

  2. normal: default size; large: large size; small: small size; ↩︎ ↩︎

  3. row: horizontal; column: vertical ↩︎ ↩︎