Checkbox
A control that is checked, unchecked, or mixed.
Checkbox follows the Checkbox WAI-ARIA design pattern.
import { component$, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@leve-ui/checkbox';
import { LuCheck } from '@qwikest/icons/lucide';
import styles from './default.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Checkbox.Root class="checkbox-default-root">
<Checkbox.Control class="checkbox-default-control">
<Checkbox.Indicator class="checkbox-default-indicator">
<LuCheck class="checkbox-default-icon" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-default-label">Accept terms and conditions</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
);
});.checkbox-default-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
font-family: inherit;
}
.checkbox-default-control {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 4px;
background: light-dark(#ffffff, #1b2045);
cursor: pointer;
}
.checkbox-default-control[data-state="checked"] {
background: #009dfd;
border-color: #009dfd;
}
.checkbox-default-control:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.checkbox-default-control:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* The indicator is always rendered; show it only when checked */
.checkbox-default-indicator {
display: none;
color: #ffffff;
}
.checkbox-default-indicator[data-state="checked"] {
display: inline-flex;
}
.checkbox-default-icon {
width: 12px;
height: 12px;
}
.checkbox-default-label {
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}Installation#
Install the individual package, or use @leve-ui/core to get every component at once:
pnpm add @leve-ui/checkboxnpm install @leve-ui/checkboxyarn add @leve-ui/checkboxbun add @leve-ui/checkboxpnpm add @leve-ui/corenpm install @leve-ui/coreyarn add @leve-ui/corebun add @leve-ui/coreAnatomy#
import { Checkbox } from '@leve-ui/checkbox'; // or '@leve-ui/core'
<Checkbox.Group>
<Checkbox.Root value="item">
<Checkbox.Control>
<Checkbox.Indicator />
</Checkbox.Control>
<Checkbox.Label />
<Checkbox.HiddenInput />
</Checkbox.Root>
</Checkbox.Group>
| Part | Element | Description |
|---|---|---|
Checkbox.Group | <div> | Optional. Manages a list of selected values across multiple checkboxes (role="group"). |
Checkbox.Root | <div> | Wraps the parts and holds the checked state. Not interactive. |
Checkbox.Control | <button> | The checkbox itself, with role="checkbox". |
Checkbox.Indicator | <span> | Holds the check mark or other icons. Always rendered. |
Checkbox.Label | <label> | The label. Clicking it toggles the checkbox. |
Checkbox.HiddenInput | <input type="checkbox"> | Optional. Sends the state with a native <form>. |
Examples#
Checked#
defaultChecked sets the initial state.
import { component$, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@leve-ui/checkbox';
import { LuCheck } from '@qwikest/icons/lucide';
import styles from './checked.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Checkbox.Root defaultChecked={true} class="checkbox-checked-root">
<Checkbox.Control class="checkbox-checked-control">
<Checkbox.Indicator class="checkbox-checked-indicator">
<LuCheck class="checkbox-checked-icon" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-checked-label">Subscribe to newsletter</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
);
});.checkbox-checked-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
font-family: inherit;
}
.checkbox-checked-control {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 4px;
background: light-dark(#ffffff, #1b2045);
cursor: pointer;
}
.checkbox-checked-control[data-state="checked"] {
background: #009dfd;
border-color: #009dfd;
}
.checkbox-checked-control:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.checkbox-checked-control:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* The indicator is always rendered; show it only when checked */
.checkbox-checked-indicator {
display: none;
color: #ffffff;
}
.checkbox-checked-indicator[data-state="checked"] {
display: inline-flex;
}
.checkbox-checked-icon {
width: 12px;
height: 12px;
}
.checkbox-checked-label {
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}Disabled#
disabled on the Root disables the checkbox.
import { component$, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@leve-ui/checkbox';
import { LuCheck } from '@qwikest/icons/lucide';
import styles from './disabled.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Checkbox.Root disabled class="checkbox-disabled-root">
<Checkbox.Control class="checkbox-disabled-control">
<Checkbox.Indicator class="checkbox-disabled-indicator">
<LuCheck class="checkbox-disabled-icon" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-disabled-label">Disabled option</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
);
});.checkbox-disabled-root {
font-family: inherit;
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
}
.checkbox-disabled-control {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 4px;
background: light-dark(#ffffff, #1b2045);
cursor: pointer;
}
.checkbox-disabled-control[data-state="checked"] {
background: #009dfd;
border-color: #009dfd;
}
.checkbox-disabled-control:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.checkbox-disabled-control:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* The indicator is always rendered; show it only when checked */
.checkbox-disabled-indicator {
display: none;
color: #ffffff;
}
.checkbox-disabled-indicator[data-state="checked"] {
display: inline-flex;
}
.checkbox-disabled-icon {
width: 12px;
height: 12px;
}
.checkbox-disabled-label {
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.checkbox-disabled-label[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}Indeterminate#
The checked state can be "indeterminate", for example for a "select all" checkbox. This demo controls the states with bind:checked and onCheckedChange$.
import { $, component$, useComputed$, useSignal, useStyles$, useTask$ } from '@builder.io/qwik';
import { Checkbox, type CheckboxCheckedState } from '@leve-ui/checkbox';
import { LuCheck, LuMinus } from '@qwikest/icons/lucide';
import styles from './indeterminate.css?inline';
export default component$(() => {
useStyles$(styles);
const child1 = useSignal(true);
const child2 = useSignal(false);
const child3 = useSignal(false);
const parent = useSignal<CheckboxCheckedState>('indeterminate');
// Synchronize parent state based on child values
useTask$(({ track }) => {
const c1 = track(() => child1.value);
const c2 = track(() => child2.value);
const c3 = track(() => child3.value);
const all = c1 && c2 && c3;
const none = !c1 && !c2 && !c3;
if (all) {
parent.value = true;
} else if (none) {
parent.value = false;
} else {
parent.value = 'indeterminate';
}
});
const selectedCount = useComputed$(() => {
return [child1.value, child2.value, child3.value].filter(Boolean).length;
});
const handleParentChange$ = $((next: CheckboxCheckedState) => {
const target = next === true;
child1.value = target;
child2.value = target;
child3.value = target;
});
return (
<div class="checkbox-indeterminate-group">
<Checkbox.Root
bind:checked={parent}
onCheckedChange$={handleParentChange$}
class="checkbox-indeterminate-root"
>
<Checkbox.Control class="checkbox-indeterminate-control">
<Checkbox.Indicator class="checkbox-indeterminate-indicator">
<LuCheck class="checkbox-indeterminate-icon-check" aria-hidden="true" />
<LuMinus class="checkbox-indeterminate-icon-indeterminate" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-indeterminate-label">Select all ingredients</Checkbox.Label>
<span class="checkbox-indeterminate-count">({selectedCount.value} of 3 selected)</span>
<Checkbox.HiddenInput />
</Checkbox.Root>
<div class="checkbox-indeterminate-group-children">
<Checkbox.Root bind:checked={child1} class="checkbox-indeterminate-root">
<Checkbox.Control class="checkbox-indeterminate-control">
<Checkbox.Indicator class="checkbox-indeterminate-indicator">
<LuCheck class="checkbox-indeterminate-icon-check" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-indeterminate-label">Lettuce</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
<Checkbox.Root bind:checked={child2} class="checkbox-indeterminate-root">
<Checkbox.Control class="checkbox-indeterminate-control">
<Checkbox.Indicator class="checkbox-indeterminate-indicator">
<LuCheck class="checkbox-indeterminate-icon-check" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-indeterminate-label">Tomato</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
<Checkbox.Root bind:checked={child3} class="checkbox-indeterminate-root">
<Checkbox.Control class="checkbox-indeterminate-control">
<Checkbox.Indicator class="checkbox-indeterminate-indicator">
<LuCheck class="checkbox-indeterminate-icon-check" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-indeterminate-label">Cheese</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
</div>
</div>
);
});.checkbox-indeterminate-group {
display: flex;
flex-direction: column;
gap: 12px;
font-family: inherit;
}
.checkbox-indeterminate-group-children {
display: flex;
flex-direction: column;
gap: 12px;
padding-left: 28px;
}
.checkbox-indeterminate-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
}
.checkbox-indeterminate-control {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 4px;
background: light-dark(#ffffff, #1b2045);
cursor: pointer;
}
.checkbox-indeterminate-control[data-state="checked"],
.checkbox-indeterminate-control[data-state="indeterminate"] {
background: #009dfd;
border-color: #009dfd;
}
.checkbox-indeterminate-control:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
/* The indicator is always rendered; show it only when checked or indeterminate */
.checkbox-indeterminate-indicator {
display: none;
color: #ffffff;
}
.checkbox-indeterminate-indicator[data-state="checked"],
.checkbox-indeterminate-indicator[data-state="indeterminate"] {
display: inline-flex;
}
.checkbox-indeterminate-icon-check,
.checkbox-indeterminate-icon-indeterminate {
display: none;
width: 12px;
height: 12px;
}
/* Check icon when checked, minus icon when indeterminate */
.checkbox-indeterminate-indicator[data-state="checked"] .checkbox-indeterminate-icon-check,
.checkbox-indeterminate-indicator[data-state="indeterminate"]
.checkbox-indeterminate-icon-indeterminate {
display: block;
}
.checkbox-indeterminate-label {
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.checkbox-indeterminate-count {
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}Group#
Checkbox.Group manages an array of selected values across multiple Checkbox.Root items. Use maxSelectedValues to limit how many items can be selected at once.
Selected: qwik
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@leve-ui/checkbox';
import { LuCheck } from '@qwikest/icons/lucide';
import styles from './group.css?inline';
export default component$(() => {
useStyles$(styles);
const selected = useSignal<string[]>(['qwik']);
return (
<div class="checkbox-group-wrapper">
<Checkbox.Group
aria-label="Frameworks (up to 2)"
name="frameworks"
defaultValue={['qwik']}
maxSelectedValues={2}
onValueChange$={(values) => {
selected.value = values;
}}
class="checkbox-group-list"
>
<Checkbox.Root value="qwik" class="checkbox-group-item">
<Checkbox.Control class="checkbox-group-control">
<Checkbox.Indicator class="checkbox-group-indicator">
<LuCheck class="checkbox-group-icon" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-group-label">Qwik</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
<Checkbox.Root value="react" class="checkbox-group-item">
<Checkbox.Control class="checkbox-group-control">
<Checkbox.Indicator class="checkbox-group-indicator">
<LuCheck class="checkbox-group-icon" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-group-label">React</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
<Checkbox.Root value="svelte" class="checkbox-group-item">
<Checkbox.Control class="checkbox-group-control">
<Checkbox.Indicator class="checkbox-group-indicator">
<LuCheck class="checkbox-group-icon" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-group-label">Svelte</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
</Checkbox.Group>
<p class="checkbox-group-status">Selected: {selected.value.join(', ') || 'none'}</p>
</div>
);
});.checkbox-group-wrapper {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.checkbox-group-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.checkbox-group-item {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
}
.checkbox-group-control {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 4px;
background: light-dark(#ffffff, #1b2045);
cursor: pointer;
}
.checkbox-group-control[data-state="checked"] {
background: #009dfd;
border-color: #009dfd;
}
.checkbox-group-control:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.checkbox-group-control:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* The indicator is always rendered; show it only when checked */
.checkbox-group-indicator {
display: none;
color: #ffffff;
}
.checkbox-group-indicator[data-state="checked"] {
display: inline-flex;
}
.checkbox-group-icon {
width: 12px;
height: 12px;
}
.checkbox-group-label {
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.checkbox-group-label[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.checkbox-group-status {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}With Field#
Inside a Field.Root, use Field.Label instead of Checkbox.Label. The Field provides the IDs, the description and the disabled / required / invalid states.
import { component$, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@leve-ui/checkbox';
import { Field } from '@leve-ui/field';
import { LuCheck } from '@qwikest/icons/lucide';
import styles from './with-field.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Field.Root hasDescription class="checkbox-with-field-field">
<div class="checkbox-with-field-row">
<Checkbox.Root class="checkbox-with-field-root">
<Checkbox.Control class="checkbox-with-field-control">
<Checkbox.Indicator class="checkbox-with-field-indicator">
<LuCheck class="checkbox-with-field-icon" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.HiddenInput />
</Checkbox.Root>
<Field.Label class="checkbox-with-field-label">Remember me</Field.Label>
</div>
<Field.Description class="checkbox-with-field-description">
Save your session on this device for 30 days.
</Field.Description>
</Field.Root>
);
});.checkbox-with-field-field {
display: flex;
flex-direction: column;
gap: 6px;
width: 280px;
font-family: inherit;
}
.checkbox-with-field-row {
display: flex;
align-items: center;
gap: 10px;
}
.checkbox-with-field-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
}
.checkbox-with-field-control {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 4px;
background: light-dark(#ffffff, #1b2045);
cursor: pointer;
}
.checkbox-with-field-control[data-state="checked"] {
background: #009dfd;
border-color: #009dfd;
}
.checkbox-with-field-control:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.checkbox-with-field-control:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* The indicator is always rendered; show it only when checked */
.checkbox-with-field-indicator {
display: none;
color: #ffffff;
}
.checkbox-with-field-indicator[data-state="checked"] {
display: inline-flex;
}
.checkbox-with-field-icon {
width: 12px;
height: 12px;
}
.checkbox-with-field-label {
font-size: 14px;
font-weight: 500;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
/* Indented to line up with the label text (control 18px + gap 10px) */
.checkbox-with-field-description {
margin: 0;
padding-left: 28px;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}With Form#
Add Checkbox.HiddenInput with name and value to submit the state with a native <form>.
import { $, component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@leve-ui/checkbox';
import { LuCheck } from '@qwikest/icons/lucide';
import styles from './with-form.css?inline';
export default component$(() => {
useStyles$(styles);
const submittedData = useSignal('');
const handleSubmit$ = $((_event: unknown, form: HTMLFormElement) => {
const formData = new FormData(form);
submittedData.value = JSON.stringify(Object.fromEntries(formData));
});
return (
<div class="checkbox-with-form-wrapper">
<form class="checkbox-with-form-form" preventdefault:submit onSubmit$={handleSubmit$}>
<Checkbox.Root class="checkbox-with-form-root">
<Checkbox.Control class="checkbox-with-form-control">
<Checkbox.Indicator class="checkbox-with-form-indicator">
<LuCheck class="checkbox-with-form-icon" aria-hidden="true" />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label class="checkbox-with-form-label">
Agree to marketing emails
</Checkbox.Label>
<Checkbox.HiddenInput name="marketing" value="subscribed" />
</Checkbox.Root>
<div class="checkbox-with-form-actions">
<button type="submit" class="checkbox-with-form-submit">
Submit
</button>
<button type="reset" class="checkbox-with-form-reset">
Reset
</button>
</div>
</form>
<output class="checkbox-with-form-output">{submittedData.value}</output>
</div>
);
});.checkbox-with-form-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
display: inline-flex;
align-items: center;
gap: 10px;
}
.checkbox-with-form-control {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 4px;
background: light-dark(#ffffff, #1b2045);
cursor: pointer;
}
.checkbox-with-form-control[data-state="checked"] {
background: #009dfd;
border-color: #009dfd;
}
.checkbox-with-form-control:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.checkbox-with-form-control:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* The indicator is always rendered; show it only when checked */
.checkbox-with-form-indicator {
display: none;
color: #ffffff;
}
.checkbox-with-form-indicator[data-state="checked"] {
display: inline-flex;
}
.checkbox-with-form-icon {
width: 12px;
height: 12px;
}
.checkbox-with-form-label {
font-size: 14px;
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.checkbox-with-form-wrapper {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.checkbox-with-form-form {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.checkbox-with-form-actions {
display: flex;
gap: 8px;
}
.checkbox-with-form-submit {
height: 32px;
padding: 0 12px;
border: none;
border-radius: 6px;
background: #009dfd;
color: #ffffff;
font: inherit;
font-size: 13px;
font-weight: 500;
cursor: pointer;
}
.checkbox-with-form-submit:hover {
background: #006ce9;
}
.checkbox-with-form-submit:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.checkbox-with-form-reset {
height: 32px;
padding: 0 12px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 13px;
font-weight: 500;
cursor: pointer;
}
.checkbox-with-form-reset:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.checkbox-with-form-reset:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.checkbox-with-form-output {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}API Reference#
Group#
| Prop | Default | Type |
|---|---|---|
| defaultValue | [] | string[] The initial selected values (uncontrolled). |
| bind:value | – | Signal<string[]> A signal with the selected values (controlled). |
| onValueChange$ | – | QRL<(value: string[]) => void> Called when the selected values change. |
| name | – | string Shared |
| disabled | false | boolean Disables all checkboxes in the group. Inside a Field or Fieldset, the inherited |
| readOnly | false | boolean Marks all checkboxes in the group as read-only. Inside a Field, the Field's |
| invalid | false | boolean Marks all checkboxes in the group as invalid. Inside a Field, the Field's |
| maxSelectedValues | – | number Maximum number of checkboxes that can be selected at once. |
Also accepts all <div> attributes.
| Data attribute | Value |
|---|---|
data-leve-checkbox-group | Always present |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
The selected values are uncontrolled with defaultValue, or controlled with bind:value. onValueChange$ is called when the user toggles an item. name, disabled, readOnly, invalid, and maxSelectedValues are shared with descendant Checkbox.Root items.
Root#
| Prop | Default | Type |
|---|---|---|
| ids | – | { control?: string; label?: string } Overrides the element IDs of the parts. Only used outside a Field (or inside a Group). |
| defaultChecked | false | boolean | 'indeterminate' The initial checked state (uncontrolled). |
| bind:checked | – | Signal<boolean | 'indeterminate'> A signal with the checked state (controlled). |
| onCheckedChange$ | – | QRL<(checked: boolean | 'indeterminate') => void> Called when the user changes the checked state. |
| disabled | false | boolean Disables the checkbox. Inside a Field, Fieldset, or Group, the inherited |
| required | false | boolean Marks the checkbox as required. Inside a Field, the Field's |
| readOnly | false | boolean Marks the checkbox as read-only. Inside a Field or Group, the inherited |
| invalid | false | boolean Marks the checkbox as invalid. Inside a Field or Group, the inherited |
| name | – | string The |
| value | – | string The value used to match against the surrounding |
Also accepts all <div> attributes.
| Data attribute | Value |
|---|---|
data-leve-checkbox | Always present |
data-state | "checked" | "unchecked" | "indeterminate" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
The checked state is uncontrolled with defaultChecked, or controlled with bind:checked. onCheckedChange$ is called when the user changes it. Toggling an "indeterminate" checkbox makes it checked. Inside a Checkbox.Group, pass value to match against the group's selected values.
Inside a Field (outside a Group), the IDs come from the Field and ids is ignored (ADR 0024). Inside a Checkbox.Group, each checkbox uses its own generated IDs (or ids) so multiple checkboxes do not share duplicate IDs.
Control#
No props of its own. Accepts all <button> attributes.
| Data attribute | Value |
|---|---|
data-leve-checkbox-control | Always present |
data-state | "checked" | "unchecked" | "indeterminate" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
Indicator#
No props of its own. Accepts all <span> attributes.
| Data attribute | Value |
|---|---|
data-leve-checkbox-indicator | Always present |
data-state | "checked" | "unchecked" | "indeterminate" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
The indicator is always rendered. Show or hide its icons with CSS, for example [data-leve-checkbox-indicator][data-state="unchecked"].
Label#
No props of its own. Accepts all <label> attributes.
| Data attribute | Value |
|---|---|
data-leve-checkbox-label | Always present |
data-state | "checked" | "unchecked" | "indeterminate" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
HiddenInput#
| Prop | Default | Type |
|---|---|---|
| form | – | string The |
Also accepts all <input> attributes.
| Data attribute | Value |
|---|---|
data-leve-checkbox-hidden-input | Always present |
data-state | "checked" | "unchecked" | "indeterminate" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
The hidden input follows the checked, required and disabled states, and inherits name and value from Checkbox.Root or Checkbox.Group, so native form submission and required validation work (ADR 0026). It is positioned absolutely with an inline style, so give Checkbox.Root position: relative.
Accessibility#
Complies with the Checkbox WAI-ARIA design pattern.
- Name the checkbox with
Checkbox.Label,Field.Label, oraria-label/aria-labelledbyonCheckbox.Control. Name aCheckbox.Groupwitharia-labeloraria-labelledby. Checkbox.Grouprendersrole="group",aria-describedby(inside a Field),aria-invalid,aria-disabled, andaria-readonly.Checkbox.Controlrendersrole="checkbox"andaria-checked("true","false"or"mixed"),aria-requiredwhen required,aria-readonlywhen read-only, andaria-invalidwhen invalid. Outside aCheckbox.Group, inside a Field it also rendersaria-describedby.- Do not change the label text with the state. The state is conveyed by
aria-checked. Checkbox.IndicatorandCheckbox.HiddenInputare hidden from assistive technologies witharia-hidden="true".
Keyboard Interactions#
| Key | Description |
|---|---|
Space | Checks or unchecks the checkbox. |
Enter | Checks or unchecks the checkbox. |