Components
Checkbox Group
A labelled fieldset of checkboxes with multi-select state.
Installation
$ npx veil-ui@latest add checkbox-groupUsage
import { CheckboxGroup } from "@/components/ui/checkbox-group";
<CheckboxGroup
label="Notifications"
options={[
{ value: "email", label: "Email" },
{ value: "sms", label: "SMS" },
]}
defaultValue={["email"]}
/>;Examples
Basic
With Descriptions
Controlled
Selected: news
API reference
The package exports checkbox-group along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.
Accessibility
CheckboxGrouprenders a labelledfieldset; keyboard focus moves through native checkbox controls.- Error and disabled states are exposed through native attributes and Radix data attributes.
- Focus-visible rings follow the shared token system in both themes.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add checkbox-group --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { computed, ref, useId } from "vue";
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
import { cn } from "@/lib/utils";
import type { CheckboxGroupOption } from "./types";
const props = withDefaults(
defineProps<{
options: CheckboxGroupOption[];
modelValue?: string[];
defaultValue?: string[];
label?: string;
disabled?: boolean;
class?: string;
}>(),
{ defaultValue: () => [], disabled: false },
);
const emit = defineEmits<{ "update:modelValue": [value: string[]] }>();
const id = useId();
const internal = ref<string[]>([...props.defaultValue]);
const selected = computed(() => props.modelValue ?? internal.value);
function toggle(value: string, checked: boolean | "indeterminate") {
const next =
checked === true
? [...selected.value, value]
: selected.value.filter((item) => item !== value);
if (props.modelValue === undefined) internal.value = next;
emit("update:modelValue", next);
}
</script>
<template>
<fieldset
data-slot="checkbox-group"
:disabled="disabled"
:class="cn('grid gap-3', props.class)"
>
<legend v-if="label" class="mb-1 text-sm font-medium">{{ label }}</legend>
<div
v-for="option in options"
:key="option.value"
class="flex items-start gap-2"
>
<Checkbox
:id="`${id}-${option.value}`"
:model-value="selected.includes(option.value)"
:disabled="disabled || option.disabled"
class="mt-0.5"
@update:model-value="(checked) => toggle(option.value, checked)"
/>
<div class="grid gap-0.5">
<Label :for="`${id}-${option.value}`">{{ option.label }}</Label>
<p v-if="option.description" class="text-sm text-muted-foreground">
{{ option.description }}
</p>
</div>
</div>
</fieldset>
</template>