Skip to main content

VCheckbox

The VCheckbox component provides a checkbox input with label, validation, and indeterminate state support. It wraps VCheckboxBtn with VInput for consistent form field styling.

Basic Usage

<template>
  <VCheckbox
    v-model="checked"
    label="I agree to the terms"
  />
</template>

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

const checked = ref(false)
</script>

Props

modelValue
any
The checkbox value. Can be boolean, array, or custom true/false values.
label
string
Label text to display next to the checkbox.
value
any
The value used when the checkbox is checked (useful for arrays).
trueValue
any
default:"true"
The value when checked in single checkbox mode.
falseValue
any
default:"false"
The value when unchecked in single checkbox mode.
indeterminate
boolean
default:"false"
Display the checkbox in an indeterminate state.
indeterminateIcon
string
default:"$checkboxIndeterminate"
Icon to display when in indeterminate state.
trueIcon
string
default:"$checkboxOn"
Icon to display when checked.
falseIcon
string
default:"$checkboxOff"
Icon to display when unchecked.
color
string
Color of the checkbox when checked.
disabled
boolean
default:"false"
Disable the checkbox.
readonly
boolean
default:"false"
Make the checkbox readonly (cannot be changed by user).
error
boolean
default:"false"
Put the checkbox in an error state.
rules
ValidationRule[]
Validation rules for the checkbox.
ripple
boolean
default:"true"
Enable ripple effect on click.

Multiple Checkboxes with Array

<template>
  <div>
    <VCheckbox
      v-model="selected"
      label="Red"
      value="red"
    />
    <VCheckbox
      v-model="selected"
      label="Green"
      value="green"
    />
    <VCheckbox
      v-model="selected"
      label="Blue"
      value="blue"
    />
    <p>Selected: {{ selected }}</p>
  </div>
</template>

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

const selected = ref([])
</script>

Custom True/False Values

<template>
  <VCheckbox
    v-model="status"
    label="Active"
    :true-value="'active'"
    :false-value="'inactive'"
  />
</template>

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

const status = ref('inactive')
</script>

Indeterminate State

<template>
  <div>
    <VCheckbox
      v-model="selectAll"
      :indeterminate="indeterminate"
      label="Select All"
      @click="toggleAll"
    />
    <VCheckbox
      v-for="item in items"
      :key="item.id"
      v-model="selected"
      :value="item.id"
      :label="item.name"
    />
  </div>
</template>

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

const items = [
  { id: 1, name: 'Item 1' },
  { id: 2, name: 'Item 2' },
  { id: 3, name: 'Item 3' },
]

const selected = ref([])
const selectAll = computed({
  get: () => selected.value.length === items.length,
  set: (value) => {
    if (value) {
      selected.value = items.map(item => item.id)
    } else {
      selected.value = []
    }
  }
})

const indeterminate = computed(() => 
  selected.value.length > 0 && selected.value.length < items.length
)

function toggleAll() {
  if (selected.value.length === items.length) {
    selected.value = []
  } else {
    selected.value = items.map(item => item.id)
  }
}
</script>

With Validation

<template>
  <VCheckbox
    v-model="agreed"
    label="I agree to the terms and conditions"
    :rules="[v => !!v || 'You must agree to continue']"
  />
</template>

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

const agreed = ref(false)
</script>

Events

update:modelValue
(value: any) => void
Emitted when the checkbox value changes.
update:focused
(focused: boolean) => void
Emitted when the focus state changes.
update:indeterminate
(value: boolean) => void
Emitted when the indeterminate state changes.

Slots

label
{ label, props }
Customize the label content.
input
{ }
Customize the input element.

Build docs developers (and LLMs) love