Skip to content
On this page

Checkbox

Augmented form field for boolean input.

Usage

See using components for detailed instructions.

js
import { CCheckbox } from 'chusho';

Config

The options below are to be set in the global configuration at the following location:

js
{
  components: {
    checkbox: {
      class: ({ checked, required, disabled, modelValue, trueValue, falseValue, variant }) => {},
    },
  },
}

class

Classes applied to the input element, except when the prop bare is set to true. See styling components.

  • type: Array<String | Object> | Object | String | (props: Object) => {}
  • default: null

Example

js
class({ checked }) {
    return ['checkbox', {
        'checkbox--checked': checked,
    }]
}

API

NameTypeDefaultDescription
Props
variant string|array|objectundefined

Useful when used in the component config class option, to style it conditionally. See styling components.

bare booleanfalse

Disable class inheritance from the component config. See styling components.

disabled booleannull

Set the HTML disabled attribute

required booleannull

Set the HTML required attribute

modelValue anynull

Bind the Checkbox state with the parent component.

trueValue anytrue

Value set when the checkbox is checked.

falseValue anyfalse

Value set when the checkbox is unchecked.

Events
update:modelValue
Emitted when the checkbox checked state changes.
ArgumentTypeDescription
modelValueany

trueValue or falseValue depending on the checkbox state.

Examples

Controlled

vue
<template>
  <CCheckbox v-model="value" />
</template>

<script>
export default {
  data() {
    return {
      value: true, // Checked by default
    };
  },
};
</script>

Controlled with custom values

vue
<template>
  <CCheckbox v-model="value" trueValue="on" falseValue="off" />
</template>

<script>
export default {
  data() {
    return {
      value: 'off', // Unchecked by default
    };
  },
};
</script>

Released under the MIT License.