WlCheckbox
Checkbox with a boolean value and slot label.
Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.
Settings
Disables the checkbox.
Indeterminate state.
Error state.
Props pt, value, size, density, models, handlers and slots can be edited in the SFC. See their descriptions in API.
Example
Focus: outside the example · pointer: outside the example
Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.
Code for your application
Vue SFC · current settings
<script setup lang="ts">
import { WlCheckbox } from "legato-ui";
import { ref } from "vue";
const value = ref(true);
const permissions = ref<number[]>([1]);
</script>
<template>
<div class="wl-stack" data-space="md">
<WlCheckbox v-model="value" >{{ "Receive updates" }}</WlCheckbox>
<fieldset class="wl-stack" data-space="sm">
<legend>{{ "Permissions" }}</legend>
<WlCheckbox v-model="permissions" :value="1" size="sm">{{ "Read" }}</WlCheckbox>
<WlCheckbox v-model="permissions" :value="2" size="sm">{{ "Share" }}</WlCheckbox>
<output aria-label="Permissions">{{ permissions.join(", ") }}</output>
</fieldset>
</div>
</template>Related checkboxes
Select all available items with calculated indeterminate, consent with an error and disabled.
Linked selection and indeterminate
The application computes the intermediate state when some child items are selected. Space toggles the focused checkbox.
Label, error and disabled
Confirm your agreement.
Notifications selected: 1 of 2. Agreement: not confirmed.
Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlCheckbox, WlField } from "legato-ui";
import { computed, ref } from "vue";
const notifications = ref([{ id: "mail", label: "Email", enabled: true }, { id: "push", label: "Push notifications", enabled: false }]);
const selectedCount = computed(() => notifications.value.filter((item) => item.enabled).length);
const allSelected = computed({
get: () => selectedCount.value === notifications.value.length,
set: (checked: boolean) => {
notifications.value.forEach((item) => {
item.enabled = checked;
});
}
});
const mixed = computed(() => selectedCount.value > 0 && !allSelected.value);
const consent = ref(false);
const permissions = ref<number[]>([1]);
const summary = computed(() =>
"Notifications selected:" + " " + selectedCount.value + " " + "of" + " "
+ notifications.value.length + ". Agreement:" + " "
+ (consent.value ? "confirmed" : "not confirmed") + "."
);
</script>
<template>
<div class="wl-stack" data-space="xl" data-input-example="WlCheckbox">
<fieldset class="wl-stack" data-space="sm">
<legend>{{ "Permissions" }}</legend>
<WlCheckbox v-model="permissions" :value="1" size="sm">{{ "Read" }}</WlCheckbox>
<WlCheckbox v-model="permissions" :value="2" size="sm">{{ "Share" }}</WlCheckbox>
<output aria-label="Permissions">{{ permissions.join(", ") }}</output>
</fieldset>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-title">{{ "Linked selection and indeterminate" }}</h3>
<WlCheckbox v-model="allSelected" :indeterminate="mixed">{{ "All available notifications" }}</WlCheckbox>
<div class="wl-stack" data-space="sm">
<WlCheckbox v-for="item in notifications" :key="item.id" v-model="item.enabled">{{ item.label }}</WlCheckbox>
</div>
<p class="wl-text-small wl-text-muted">{{ "The application computes the intermediate state when some child items are selected. Space toggles the focused checkbox." }}</p>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-title">{{ "Label, error and disabled" }}</h3>
<WlField
id="docs-checkbox-consent"
v-slot="{ id, ariaDescribedby, invalid }"
:error="consent ? undefined : 'Confirm your agreement.'"
><WlCheckbox
:id="id"
v-model="consent"
:invalid="invalid"
:aria-describedby="ariaDescribedby"
required
>{{ "I agree to the terms" }}</WlCheckbox></WlField>
<WlCheckbox :model-value="true" disabled>{{ "System notifications are required" }}</WlCheckbox>
<WlButton size="sm" @click="allSelected = false; consent = false">{{ "Clear available checkboxes" }}</WlButton>
<p class="wl-text-small" role="status">{{ summary }}</p>
</section>
</div>
</template>