Skip to content

Checkbox Component

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

📌 Platform Difference Notes

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

🏯 Basic Usage Example

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>

Standalone Single

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 set the checkboxes to horizontal or vertical arrangement 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 Two-Ends Arrangement

You can set the alignment of the checkbox icon to left-aligned or right-aligned 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, passed value is label
  • icon: custom icon inside the option box, 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-
columnsReceives array valuearray-
fieldNamesCustom keys for columnsobject{label: "label",value: "value",checked: "checked"}
shapeCheckbox shape[1]circle|squaresquare
sizeCheckbox size[2]small|medium|large |string|numbermedium
disabledWhether disabledbooleanfalse
activeColorColor in selected statestring-
inactiveColorColor in unselected statestring#c8c9cc
iconSizeIcon size, default unit is px for numeric valuesstring|number20
iconColorIcon colorstring-
labelSizelabel font size, default unit is px for numeric valuesstring|number-
labelColorlabel colorstring-
iconPlacementAlignment of the checkbox iconleft|rightleft
borderBottomWhether to show the bottom line in vertical arrangementbooleanfalse
labelDisabledWhether to disable selecting the checkbox by clicking the labelbooleanfalse
placementLayout method[3]row|columnrow
customStyleDefine external styles to be usedCSSProperties-

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 disabledbooleanfalse
activeColorColor in selected statestring-
inactiveColorColor in unselected statestring#c8c9cc
iconSizeIcon size, unit is pxstring|number20
iconColorIcon colorstring-
labelSizelabel font size, unit is pxstring|number-
labelColorlabel colorstring-
iconPlacementAlignment of the checkbox iconleft|rightleft
borderBottomWhether to show the bottom line in vertical arrangementbooleanfalse
labelDisabledWhether to disable selecting the checkbox by clicking the labelbooleanfalse
placementLayout method[3:1]row|columnrow
customStyleDefine external styles to be usedCSSProperties-

CheckboxItem Props

ParameterDescriptionTypeDefault
valueBinding valuestring-
labellabel textstring-
checkedWhether selected by defaultbooleanfalse
disabledWhether disabledbooleanfalse

columns

ParameterDescriptionTypeDefault
labelDisplay text contentstring-
valueValuestring-
checkedWhether selectedboolean-
disabledWhether disabledboolean-

API

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

CheckboxItem Events

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

CheckboxItem Slots

Slot NameDescriptionPassed Value
iconCustom icon contenticonColor | iconSize
labelCustom label contentrecord
03:29

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

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

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