CheckboxGroup
A group of checkboxes for multi-select. Supports list/card variants, horizontal/vertical orientation, legend, descriptions, and controlled state with bind:value.
<id>-<value>. They come from the component instance, so two groups that share an id or a field name keep their items apart: clicking a label or a card selects the item of its own group, and the ids match between server and client. The id prop now lands on the fieldset, so the group can be selected by it. Items with variant="card" are now named by their label, and item descriptions are announced in both variants. A selector that targeted an item by its id needs the change below./* Before 2.10.0: items were named <id>-<value> */
#toppings-cheese {
outline-offset: 2px;
}
/* From 2.10.0: item ids are generated. Reach the items through the
group, whose id you set */
#toppings [role="checkbox"] {
outline-offset: 2px;
}
/* In a test, find one item by its label instead:
getByRole('checkbox', { name: 'Cheese' }) */Playground
Experiment with different props in real-time.
Selected: none
Basic Usage
Pass an array of items and use bind:value for the selected values.
<script lang="ts">
import { CheckboxGroup } from 'sv5ui';
let value = $state<string[]>([]);
const items = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'orange', label: 'Orange' }
];
</script>
<CheckboxGroup {items} bind:value />With Legend & Description
Add a legend and per-item description.
<CheckboxGroup
legend="Notification preferences"
items={[
{ value: 'email', label: 'Email', description: 'Receive notifications via email' },
{ value: 'sms', label: 'SMS', description: 'Receive notifications via text message' },
{ value: 'push', label: 'Push', description: 'Receive push notifications on your device' }
]}
bind:value
/>Variants
2 visual styles.
<!-- List variant (default) -->
<CheckboxGroup variant="list" legend="List" {items} />
<!-- Card variant -->
<CheckboxGroup variant="card" legend="Card" {items} />Indicator Position
Control where the checkbox indicator appears.
<CheckboxGroup indicator="start" legend="Start" {items} />
<CheckboxGroup indicator="end" legend="End" {items} />
<CheckboxGroup indicator="hidden" legend="Hidden" {items} />Orientation
Vertical or horizontal layout.
<!-- Vertical (default) -->
<CheckboxGroup orientation="vertical" {items} />
<!-- Horizontal -->
<CheckboxGroup orientation="horizontal" {items} />Sizes
5 sizes.
<CheckboxGroup size="xs" legend="Extra Small" {items} />
<CheckboxGroup size="sm" legend="Small" {items} />
<CheckboxGroup size="md" legend="Medium" {items} />
<CheckboxGroup size="lg" legend="Large" {items} />
<CheckboxGroup size="xl" legend="Extra Large" {items} />Colors
8 semantic color schemes.
<CheckboxGroup color="primary" {items} value={['apple']} />
<CheckboxGroup color="success" {items} value={['apple']} />
<CheckboxGroup color="warning" {items} value={['apple']} />
<CheckboxGroup color="error" {items} value={['apple']} />Disabled
Disable the entire group or individual items.
<!-- Disable entire group -->
<CheckboxGroup disabled {items} />
<!-- Disable individual items -->
<CheckboxGroup items={[
{ value: 'active', label: 'Active option' },
{ value: 'disabled', label: 'Disabled option', disabled: true },
{ value: 'another', label: 'Another active option' }
]} />Loading
Show spinner and disable interaction.
<CheckboxGroup loading {items} />Custom Icon
Replace the default check icon.
<CheckboxGroup icon="lucide:heart" color="error" {items} value={['apple', 'banana']} />Controlled
Use bind:value for two-way binding.
Selected: email
<script lang="ts">
import { CheckboxGroup } from 'sv5ui';
let value = $state(['email']);
const items = [
{ value: 'email', label: 'Email' },
{ value: 'sms', label: 'SMS' },
{ value: 'push', label: 'Push' }
];
</script>
<CheckboxGroup {items} bind:value />
<p>Selected: {value.join(', ') || 'none'}</p>Card Grid
Combine card variant with horizontal orientation for a grid selection layout.
<CheckboxGroup
variant="card"
orientation="horizontal"
legend="Choose your plan"
items={[
{ value: 'free', label: 'Free', description: '5GB storage' },
{ value: 'pro', label: 'Pro', description: '50GB storage' },
{ value: 'team', label: 'Team', description: 'Unlimited' }
]}
bind:value
/>Accessibility
A group with a legend is named by it. Without one, pass aria-label. It lands on the fieldset, where assistive technology looks for it, along with the other naming and describing attributes: aria-label, aria-labelledby, aria-describedby, aria-invalid, aria-required, aria-errormessage and aria-details. class, style, data-* and aria-hidden stay on the wrapper.
<!-- No legend: name the group yourself -->
<CheckboxGroup aria-label="Toppings" items={toppings} value={['cheese']} orientation="horizontal" />onfocus and onblur describe the group as a whole: each runs once, when focus enters the group and when it leaves, not on every move between checkboxes. Inside a FormField the field label names a group that has no legend, and the description is announced.
Each item is named by its label and described by its description, in both the list and the card variant. An item whose label comes from labelSlot has no accessible name, because the slot content is not linked to it.
UI Slots
Use the ui prop to override classes on internal elements.
| Slot | Description |
|---|---|
root | Outermost wrapper |
fieldset | Main container for all items |
legend | Legend text above the group |
item | Each individual checkbox item container |
base | The checkbox box itself |
container | Visual box holding the indicator |
indicator | Inner element shown when checked |
icon | Icon inside the indicator |
wrapper | Wraps label and description text |
label | Primary text label |
description | Secondary helper text |
Snippets
| Snippet | Description |
|---|---|
legendSlot | Custom legend rendering |
labelSlot | Custom label for each item |
descriptionSlot | Custom description for each item |
Props
| Prop | Type | Default |
|---|---|---|
items | CheckboxGroupItem[] | - |
value | string[] | [] |
onValueChange | (value) => void | - |
variant | 'list' | 'card' | 'list' |
indicator | 'start' | 'end' | 'hidden' | 'start' |
orientation | 'vertical' | 'horizontal' | 'vertical' |
color | ColorType | 'primary' |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
legend | string | - |
icon | string | 'lucide:check' |
loading | boolean | false |
loadingIcon | string | icons.loading |
disabled | boolean | false |
required | boolean | false |
name | string | - |
id | string | - |
ref | HTMLElement | null | null |
class | string | - |
ui | Record<Slot, Class> | - |
Item Props
| Prop | Type | Default |
|---|---|---|
value | string | - |
label | string | - |
description | string | - |
disabled | boolean | false |