Skip to content

Checkbox

MCheckbox is a checkbox component used to provide multi-selection functionality. Users can select or deselect an option by clicking the checkbox.

Basic usage

CHECKBOX
CHECKBOX
js
<script setup>
    import { ref } from 'vue'
    const checked = ref(false);
</script>

<template>
  <m-checkbox v-model="checked"> CHECKBOX </m-checkbox>
  <m-checkbox v-model="checked" label="CHECKBOX" />
</template>

Checkbox with array

All Selected
You selected: [ "Volvo", "Mercedes" ]
Volvo
Saab
Mercedes
Audi
vue
<script setup>
import { ref, watch } from "vue";
const cars = ref(["Volvo", "Saab", "Mercedes", "Audi"]);
const selectedCars = ref(["Volvo", "Mercedes"]);
const indeterminate = ref(true);
const checkAll = ref(false);

const onCheckAllChange = (checked) => {
  checkAll.value = checked;
  selectedCars.value = checked ? cars.value : [];
};

watch(selectedCars, (val) => {
  if (val.length === cars.value.length) {
    indeterminate.value = false;
    checkAll.value = true;
  } else if (val.length === 0) {
    indeterminate.value = false;
    checkAll.value = false;
  } else {
    indeterminate.value = true;
    checkAll.value = false;
  }
});
</script>
html
<template>
  <m-checkbox
  v-model="checkAll"
  @change="onCheckAllChange"
  :indeterminate="indeterminate"
  >All Selected</m-checkbox
>
  <div>You selected: {{ selectedCars }}</div>
  <m-checkbox v-model="selectedCars" v-for="item in cars" :value="item" :label="item" />
</template>

Disabled

CHECKBOX
CHECKBOX
html
<template>
  <m-checkbox v-model="checked" disabled> CHECKBOX </m-checkbox>
  <m-checkbox v-model="checked" label="CHECKBOX" disabled />
</template>

Size

CHECKBOX
CHECKBOX
CHECKBOX
html
<template>
  <m-checkbox v-model="checked" size="mini"> CHECKBOX </m-checkbox>
  <m-checkbox v-model="checked" label="CHECKBOX" size="small" />
  <m-checkbox v-model="checked" label="CHECKBOX" size="large" />
</template>

API

For more information, please refer to the API documentation.

PropertyDescriptionTypeDefault
checkedwhether the checkbox is selectedbooleanfalse
modelValuebinding valueboolean / string / number / any[]-
valuethe value of the checkboxboolean / string / number-
disabledwhether the checkbox is disabledbooleanfalse
sizethe size of the checkboxsmall large minismall

Events

Event NameDescriptionParameters
changetriggers when the checkbox is selected or deselected(checked: boolean)

Released under the MIT License.