Skip to content

Checkbox ​

A single checkbox built on a native <input type="checkbox">. It supports a label, a description and a mixed state for "select all" checkboxes, and links itself to a parent SuFormField.

For a list of options, use CheckboxGroup.

Usage ​

Basic checkbox ​

With a label

vue
<script setup>
import { ref } from 'vue'

const newsletter = ref(false)
</script>

<template>
  <SuCheckbox v-model="newsletter" label="Subscribe to the newsletter" />
</template>

With a description ​

The description is linked to the checkbox with aria-describedby.

vue
<SuCheckbox
  v-model="notifications"
  label="Email notifications"
  description="A weekly summary of your projects' activity."
/>

Mixed state (select all) ​

v-model:indeterminate shows a dash and is announced as "partially checked". The first click clears it.

vue
<script setup>
import { computed, ref } from 'vue'

const languages = ref([
  { id: 'fr', label: 'French', checked: true },
  { id: 'en', label: 'English', checked: false }
])
const count = computed(() => languages.value.filter((l) => l.checked).length)
const all = computed({
  get: () => count.value === languages.value.length,
  set: (value) => languages.value.forEach((l) => (l.checked = value))
})
const partial = computed(() => count.value > 0 && count.value < languages.value.length)
</script>

<template>
  <SuCheckbox v-model="all" :indeterminate="partial" label="All languages" />
  <SuCheckbox v-for="l in languages" :key="l.id" v-model="l.checked" :label="l.label" />
</template>

Cards ​

vue
<SuCheckbox v-model="backup" display-type="block-card" label="Daily backup" description="Kept for 30 days." />

Sizes and states ​

vue
<SuCheckbox size="sm" label="Small" />
<SuCheckbox state="error" label="Error" />
<SuCheckbox disabled label="Disabled" />

In a FormField ​

The checkbox takes the field's id, message, state and required flag.

vue
<SuFormField label="Terms" message="You must accept the terms." state="error" required>
  <SuCheckbox v-model="accepted" label="I accept the terms of use" />
</SuFormField>

API ​

Props ​

PropTypeDefaultDescription
modelValuebooleanfalseChecked state (v-model)
indeterminatebooleanfalseMixed state (v-model:indeterminate), cleared on first click
labelstring-Label (or default slot)
descriptionstring-Help text linked with aria-describedby (or description slot)
valuestring | number-Value submitted with the form when checked
namestring-Form field name
size'sm' | 'md' | 'lg''md'Size
state'default' | 'error' | 'success' | 'warning''default'Validation state
displayType'default' | 'inline-card' | 'block-card''default'Plain or card display
disabledbooleanfalseDisables the checkbox
requiredbooleanfalseRequired checkbox
ariaLabelstring-Accessible name of a checkbox without a label

Events ​

EventPayloadDescription
update:modelValuebooleanNew value (v-model)
update:indeterminatebooleanEnd of the mixed state
changebooleanChanged by the user
focus / blurFocusEventCheckbox focus

Slots ​

SlotDescription
defaultLabel
descriptionHelp text

Exposed methods ​

MethodDescription
focus()Focuses the checkbox

Accessibility ​

  • Native input, visually hidden but focusable: Tab to focus, Space to toggle.
  • The mixed state uses the native indeterminate property, read as "partially checked" by screen readers.
  • The description is linked with aria-describedby, like the parent SuFormField message.
  • A checkbox without a visible label needs an aria-label.
  • error state: aria-invalid="true".

Publié sous licence MIT.