vael-ui v0.5.7

Forms & inputs

Layout

Checkbox

A box for one yes or no choice, with an optional indeterminate state. Use it when each choice is independent of the others.

Validating a form? vael-form wires this up with a schema

Install

import { Checkbox } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Checkbox } from 'vael-ui'

const value = ref(false)
</script>

<template>
  <Checkbox label="Checkbox label" v-model="value" />
</template>

Props

NameTypeDefaultDescription
labelstringLabel text; the default slot replaces it.
valuestring | numberValue added to an array model when checked. Checked state reflects its membership.
indeterminatebooleanfalseShows the mixed (indeterminate) state, which takes precedence over checked.
disabledbooleanfalseDisables the checkbox and blocks interaction.
invalidbooleanfalseShows the invalid state. A surrounding Field in error sets it too.
size'sm' | 'md''md'Control size.
namestringNative name for form submission.
motionCheckboxMotiontrueHow it moves: its appearance ({ initial: { control: { opacity: 0, scale: 0.8 } } }) and its states, like checked, indeterminate or invalid ({ states: { checked: { control: { scale: '1.1' } } } }). false turns its own animation off, built-in transitions too; animate the exposed boxEl/checkEl yourself.
uiPartial<Record<'root' | 'box' | 'label', UiPartValue>>Class and style overrides for each part.
modelValueboolean | unknown[]falseChecked state. Bind an array to add or remove this checkbox's value in it (checkbox group).

Events

NameTypeDescription
update:modelValue(value: boolean | unknown[])Fires when modelValue changes (v-model).
change(checked: boolean)Fires when you toggle the checkbox, with its new checked state.

Slots

NameTypeDescription
defaultanyLabel content; replaces the label text.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
inputElHTMLInputElement | nullNative checkbox input.
boxElHTMLElement | nullVisual box element.
checkElSVGElement | nullCheck-mark SVG element.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Checkbox: its appearance and states.

<Checkbox
  :motion="{ states: { checked: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootcontrolindicatorlabelSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statescheckeduncheckedindeterminateinvaliddisabledfocusactivehoverSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Checkbox pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
SpaceChecks or unchecks it.
  • A native checkbox inside a <label>, so the label prop or the default slot names it.
  • indeterminate sets the native mixed state, which screen readers announce.
  • Inside a Field, the description and error are linked with aria-describedby, and it sets aria-invalid and aria-required.
  • id and aria-* attributes you pass go to the input.