Checkbox
Customizable checkbox input element.
Preview
Installation
npx sigma-ui@latest add checkboxUsage
<script setup lang="ts">
import { ref } from 'vue';
import { Checkbox } from '@/components/ui/checkbox';
const termsAccepted = ref<boolean | 'indeterminate'>(false);
</script>
<template>
<Checkbox
id="terms"
v-model="termsAccepted"
label="Accept terms and conditions"
/>
</template>- Use
v-modelto control the checked state. It istrue,false, or'indeterminate'. labelanddescriptionrender a label and helper text next to the checkbox. Pass anidso the label is linked to the checkbox.
Examples
Basic
Custom label and description
Disabled
Form
Read the vee-validate docs to learn more about form validation.
API Reference
Checkbox
Props
| Prop | Type | Default |
|---|---|---|
labelText label rendered next to the checkbox. | string | - |
descriptionSecondary text rendered below the label. | string | - |
idId of the element | string | - |
defaultValueThe value of the checkbox when it is initially rendered. Use when you do not need to control its value. | boolean | "indeterminate" | - |
modelValueThe controlled value of the checkbox. Can be binded with v-model. | boolean | "indeterminate" | null | - |
disabledWhen | boolean | - |
valueThe value given as data when submitted with a | AcceptableValue | "on" |
trueValueThe value used when the checkbox is checked. Defaults to | boolean | - |
falseValueThe value used when the checkbox is unchecked. Defaults to | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value of the checkbox changes. | [value: boolean | "indeterminate"] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Adheres to the tri-state Checkbox WAI-ARIA design pattern. Reka UI renders a button with role="checkbox" and aria-checked.
| Key | Description |
|---|---|
| Tab | Moves focus to the checkbox. |
| Space | Checks or unchecks the checkbox. |