A set of checkboxes that share one value: the list of the checked checkboxes' values.
Import
import { CheckboxGroup } from "@kobalte/core/checkbox-group";// orimport { Root, Label, Description, ErrorMessage } from "@kobalte/core/checkbox-group";The checkboxes themselves are regular Checkbox components.
Features
- Manages the checked values of every
Checkboxinside it, controlled or uncontrolled. - Submits every checked value under the group
namewith its owning form. - Passes its
disabled,readOnlyandvalidationStatedown to every checkbox. - Optional "select all" parent checkbox, which is indeterminate while only some values are checked.
- Syncs with form reset events.
- Labeling support for assistive technology, with description and error message help text.
Anatomy
The checkbox group consists of:
- CheckboxGroup: The root container, rendered with
role="group". - CheckboxGroup.Label: The label that gives the user information on the checkbox group.
- CheckboxGroup.Description: The description that gives the user more information on the checkbox group.
- CheckboxGroup.ErrorMessage: The error message that gives the user information about how to fix a validation error on the checkbox group.
- Checkbox: Any number of checkboxes, each with a
value. See Checkbox for its parts.
<CheckboxGroup> <CheckboxGroup.Label /> <Checkbox parent>...</Checkbox> <Checkbox value="a">...</Checkbox> <Checkbox value="b">...</Checkbox> <CheckboxGroup.Description /> <CheckboxGroup.ErrorMessage /></CheckboxGroup>Example
import { Checkbox } from "@kobalte/core/checkbox";import { CheckboxGroup } from "@kobalte/core/checkbox-group";import type { ComponentProps } from "@solidjs/web";import { createSignal, For } from "solid-js";import { CheckIcon } from "../components";import style from "./checkbox-group.module.css";
const TOPPINGS = [ { value: "cheese", label: "Cheese" }, { value: "mushrooms", label: "Mushrooms" }, { value: "olives", label: "Olives" },];
const ALL_TOPPINGS = TOPPINGS.map((topping) => topping.value);
function MinusIcon(props: ComponentProps<"svg">) { return ( <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" {...props} > <path d="M2.25 7.5C2.25 7.22386 2.47386 7 2.75 7H12.25C12.5261 7 12.75 7.22386 12.75 7.5C12.75 7.77614 12.5261 8 12.25 8H2.75C2.47386 8 2.25 7.77614 2.25 7.5Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" /> </svg> );}
function Item(props: { value: string; label: string }) { return ( <Checkbox class={style.checkbox} value={props.value}> <Checkbox.Input class={style.checkbox__input} /> <Checkbox.Control class={style.checkbox__control}> <Checkbox.Indicator> <CheckIcon /> </Checkbox.Indicator> </Checkbox.Control> <Checkbox.Label class={style.checkbox__label}> {props.label} </Checkbox.Label> </Checkbox> );}
export function BasicExample() { return ( <CheckboxGroup class={style["checkbox-group"]} defaultValue={["cheese"]}> <CheckboxGroup.Label class={style["checkbox-group__label"]}> Toppings </CheckboxGroup.Label> <div class={style["checkbox-group__items"]}> <For each={TOPPINGS}> {(topping) => <Item value={topping.value} label={topping.label} />} </For> </div> </CheckboxGroup> );}
export function ControlledExample() { const [value, setValue] = createSignal<string[]>(["mushrooms"]);
return ( <> <CheckboxGroup class={style["checkbox-group"]} value={value()} onChange={setValue} > <CheckboxGroup.Label class={style["checkbox-group__label"]}> Toppings </CheckboxGroup.Label> <div class={style["checkbox-group__items"]}> <For each={TOPPINGS}> {(topping) => <Item value={topping.value} label={topping.label} />} </For> </div> </CheckboxGroup> <p class={style["checkbox-group__output"]}> Your toppings: {value().join(", ") || "none"}. </p> </> );}
export function SelectAllExample() { return ( <CheckboxGroup class={style["checkbox-group"]} allValues={ALL_TOPPINGS}> <CheckboxGroup.Label class={style["checkbox-group__label"]}> Toppings </CheckboxGroup.Label> <Checkbox class={style.checkbox} parent> {(state) => ( <> <Checkbox.Input class={style.checkbox__input} /> <Checkbox.Control class={style.checkbox__control}> <Checkbox.Indicator> {state.indeterminate() ? <MinusIcon /> : <CheckIcon />} </Checkbox.Indicator> </Checkbox.Control> <Checkbox.Label class={style.checkbox__label}> Select all </Checkbox.Label> </> )} </Checkbox> <div class={`${style["checkbox-group__items"]} ${style["checkbox-group__items--nested"]}`} > <For each={TOPPINGS}> {(topping) => <Item value={topping.value} label={topping.label} />} </For> </div> </CheckboxGroup> );}
export function ErrorMessageExample() { const [value, setValue] = createSignal<string[]>([]);
return ( <CheckboxGroup class={style["checkbox-group"]} value={value()} onChange={setValue} validationState={value().length === 0 ? "invalid" : "valid"} > <CheckboxGroup.Label class={style["checkbox-group__label"]}> Toppings </CheckboxGroup.Label> <div class={style["checkbox-group__items"]}> <For each={TOPPINGS}> {(topping) => <Item value={topping.value} label={topping.label} />} </For> </div> <CheckboxGroup.ErrorMessage class={style["checkbox-group__error-message"]} > Pick at least one topping. </CheckboxGroup.ErrorMessage> </CheckboxGroup> );}
export function HTMLFormExample() { let formRef!: HTMLFormElement; const [submitted, setSubmitted] = createSignal<string[]>();
const onSubmit = (e: SubmitEvent) => { e.preventDefault(); e.stopPropagation();
setSubmitted(new FormData(formRef).getAll("toppings") as string[]); };
return ( <form ref={formRef} onSubmit={onSubmit} class={style.form}> <CheckboxGroup class={style["checkbox-group"]} name="toppings" defaultValue={["olives"]} > <CheckboxGroup.Label class={style["checkbox-group__label"]}> Toppings </CheckboxGroup.Label> <div class={style["checkbox-group__items"]}> <For each={TOPPINGS}> {(topping) => <Item value={topping.value} label={topping.label} />} </For> </div> </CheckboxGroup> <div class={style.form__actions}> <button type="reset" class="kb-button"> Reset </button> <button type="submit" class="kb-button-primary"> Submit </button> </div> <p class={style["checkbox-group__output"]}> Submitted: {submitted()?.join(", ") ?? "nothing yet"} </p> </form> );}.checkbox-group { display: flex; flex-direction: column; gap: 12px;}
.checkbox-group__label { color: hsl(240 6% 10%); font-size: 14px; font-weight: 500; user-select: none;}
.checkbox-group__items { display: flex; flex-direction: column; gap: 8px;}
.checkbox-group__items--nested { padding-left: 26px;}
.checkbox-group__error-message { color: hsl(0 72% 51%); font-size: 12px; user-select: none;}
.checkbox-group__output { margin-top: 16px; font-size: 14px;}
.checkbox { display: inline-flex; align-items: center;}
.checkbox__control { display: flex; align-items: center; justify-content: center; height: 20px; width: 20px; border-radius: 6px; border: 1px solid hsl(240 5% 84%); background-color: hsl(240 6% 90%);}
.checkbox__input:focus-visible + .checkbox__control { outline: 2px solid hsl(200 98% 39%); outline-offset: 2px;}
.checkbox__control[data-checked],.checkbox__control[data-indeterminate] { border-color: hsl(200 98% 39%); background-color: hsl(200 98% 39%); color: white;}
.checkbox__control[data-invalid] { border-color: hsl(0 72% 51%);}
.checkbox__control[data-disabled] { opacity: 0.5;}
.checkbox__label { margin-left: 6px; color: hsl(240 6% 10%); font-size: 14px; user-select: none;}
.form { display: flex; flex-direction: column; align-items: center; gap: 24px;}
.form__actions { display: flex; gap: 8px;}
[data-theme*="dark"] .checkbox-group__label,[data-theme*="dark"] .checkbox__label { color: hsl(240 5% 84%);}
[data-theme*="dark"] .checkbox__control { border-color: hsl(240 5% 34%); background-color: hsl(240 5% 26%);}
[data-theme*="dark"] .checkbox__control[data-checked],[data-theme*="dark"] .checkbox__control[data-indeterminate] { border-color: hsl(200 98% 39%); background-color: hsl(200 98% 39%); color: hsl(0 100% 100% / 0.9);}
[data-theme*="dark"] .checkbox__control[data-invalid] { border-color: hsl(0 72% 51%);}Usage
Default value
An initial, uncontrolled value can be provided using the defaultValue prop. Every checkbox inside a group needs a value; its own checked and defaultChecked props are ignored.
<CheckboxGroup defaultValue={["cheese"]}> <Checkbox value="cheese">...</Checkbox> <Checkbox value="mushrooms">...</Checkbox></CheckboxGroup>Controlled value
The value prop can be used to make the checked values controlled. The onChange event is fired when the user checks or unchecks a checkbox, and receives the new list of values.
Your toppings: mushrooms.
import { createSignal } from "solid-js";
function ControlledExample() { const [value, setValue] = createSignal(["mushrooms"]);
return ( <> <CheckboxGroup value={value()} onChange={setValue}> ... </CheckboxGroup> <p>Your toppings: {value().join(", ") || "none"}.</p> </> );}Select all
A Checkbox with the parent prop checks or unchecks every value listed in the group's allValues prop. It is checked when all of them are checked, and indeterminate when only some are. Values that are not in allValues are left alone. The parent checkbox has no name, so it is never submitted with the form.
<CheckboxGroup allValues={["cheese", "mushrooms", "olives"]}> <Checkbox parent> {(state) => ( <> <Checkbox.Input /> <Checkbox.Control> <Checkbox.Indicator>{state.indeterminate() ? <MinusIcon /> : <CheckIcon />}</Checkbox.Indicator> </Checkbox.Control> <Checkbox.Label>Select all</Checkbox.Label> </> )} </Checkbox> <Checkbox value="cheese">...</Checkbox> <Checkbox value="mushrooms">...</Checkbox> <Checkbox value="olives">...</Checkbox></CheckboxGroup>Error message
The CheckboxGroup.ErrorMessage component can be used to help the user fix a validation error. It should be combined with the validationState prop, which is also applied to every checkbox in the group.
function ErrorMessageExample() { const [value, setValue] = createSignal<string[]>([]);
return ( <CheckboxGroup value={value()} onChange={setValue} validationState={value().length === 0 ? "invalid" : "valid"} > ... <CheckboxGroup.ErrorMessage>Pick at least one topping.</CheckboxGroup.ErrorMessage> </CheckboxGroup> );}HTML forms
Each checked checkbox submits its value under the group's name, so the form data holds one entry per checked value. Resetting the form restores defaultValue.
<form onSubmit={onSubmit}> <CheckboxGroup name="toppings" defaultValue={["olives"]}> ... </CheckboxGroup> <button type="reset">Reset</button> <button type="submit">Submit</button></form>API Reference
CheckboxGroup
CheckboxGroup is equivalent to the Root import from @kobalte/core/checkbox-group.
| Prop | Description |
|---|---|
| value | string[] The controlled values of the checked checkboxes. |
| defaultValue | string[] The values of the checkboxes that should be checked when initially rendered. Useful when you do not need to control the state. |
| onChange | (value: string[]) => void Event handler called when the checked values change. |
| allValues | string[] Every value a "select all" Checkbox (with the parent prop) controls. Required for the parent checkbox to work. |
| name | string The name every checked checkbox submits its value under with its owning form. |
| validationState | 'valid' | 'invalid' Whether the checkbox group should display its "valid" or "invalid" visual styling. Applied to every checkbox. |
| required | boolean Whether the user must check at least one checkbox. Presentational only ( data-required): it is not passed to the native inputs. |
| disabled | boolean Whether every checkbox in the group is disabled. |
| readOnly | boolean Whether every checkbox in the group can be focused but not changed by the user. |
| Data attribute | Description |
|---|---|
| data-valid | Present when the checkbox group is valid according to the validation rules. |
| data-invalid | Present when the checkbox group is invalid according to the validation rules. |
| data-required | Present when the checkbox group is required. |
| data-disabled | Present when the checkbox group is disabled. |
| data-readonly | Present when the checkbox group is read only. |
CheckboxGroup.Label, CheckboxGroup.Description and CheckboxGroup.ErrorMessage share the same data-attributes.
Checkbox (inside a group)
| Prop | Description |
|---|---|
| value | string The value added to the group's value when the checkbox is checked. Required inside a group. |
| parent | boolean Whether the checkbox is the group's "select all" checkbox. Its state is derived from allValues, and it is not submitted with the form. |
A checkbox's own disabled, readOnly and validationState props are combined with the group's.
CheckboxGroup.ErrorMessage
| Prop | Description |
|---|---|
| forceMount | boolean Used to force mounting when more control is needed. Useful when controlling animation with SolidJS animation libraries. |
Rendered elements
| Component | Default rendered element |
|---|---|
CheckboxGroup | div |
CheckboxGroup.Label | span |
CheckboxGroup.Description | div |
CheckboxGroup.ErrorMessage | div |
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
| Tab | Moves focus to the next checkbox. |
| Space | Toggles the focused checkbox on and off. |
Last updated: 12/4/26, 3:58 PM