Skip to content

Components / Checkbox

Checkbox

An independent choice, clearly marked. A square Checkbox with unchecked, checked and indeterminate states, native form integration and a visible keyboard focus ring.

Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.

Usage playground

A labeled choice with checked, unchecked and mixed states. Change the controls or activate the live checkbox; copied sample always matches the current settings.

React / TSX
'use client';

import { useId, useState } from 'react';
import { Checkbox } from '@/components/ui/yads-checkbox';
import { Label } from '@/components/ui/yads-label';

Installation

pnpm dlx [email protected] add biehlio/yet-another-design-system/checkbox#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

Documentation samples use basic Tailwind utilities for layout. Install each YADS component imported by the sample.

Run this revision-pinned GitHub command in a project configured for shadcn. It installs yads-checkbox, its scoped stylesheet, @radix-ui/react-checkbox and clsx. No separate theme install, Label component or icon package is needed.

Import { Checkbox } from @/components/ui/yads-checkbox (adjust the alias to your project). Each Copy sample includes a complete React module, even when collapsed, with YADS Label, Button where needed, and all recipe CSS. Interactive examples use a client boundary in React Server Component apps.

Indeterminate select all

Derive the mixed state from the selected children. Activating a mixed parent selects every option; activating a checked parent clears them.

Download formats
React / TSX
'use client';

import { useId, useState } from 'react';
import { Checkbox } from '@/components/ui/yads-checkbox';
import { Label } from '@/components/ui/yads-label';

Forms and disabled states

Uncontrolled inputs reset to defaultChecked. Only enabled, checked, named controls enter FormData; required uses native validation. Disabled controls keep their state and leave the tab order.

Not submitted.

React / TSX
'use client';

import { useState } from 'react';
import { Button } from '@/components/ui/yads-button';
import { Checkbox } from '@/components/ui/yads-checkbox';
import { Label } from '@/components/ui/yads-label';

Customization

Add a className with ordinary CSS. This recipe changes dimensions and border style while keeping the checked indicator, disabled treatment and focus ring. Styles are scoped; no global theme installation is required. A dark ancestor selects the dark palette.

React / TSX
import { Checkbox } from '@/components/ui/yads-checkbox';
import { Label } from '@/components/ui/yads-label';

export default function CustomCheckbox() {
  return (
    <>

Accessibility

  • Label every choice. Use a native label wrapping the checkbox or a label with htmlFor matching its unique id. Use aria-label or aria-labelledby when a visible label is not possible. Associate descriptions and errors with aria-describedby.
  • Keep keyboard access. Tab focuses enabled controls; Space toggles them. Enter does not toggle a Checkbox. The visible focus ring is preserved in both themes. Disabled controls cannot activate and are skipped by Tab; explain why an option is unavailable in nearby text.
  • Expose mixed state. Radix reports role=checkbox and aria-checked as true, false or mixed. The dash is decorative. Use indeterminate for a partially selected group, not as a third independent preference. Group related choices with a fieldset and legend.
  • Use the right primitive. Checkboxes represent independent choices, often saved with a form; switches represent an immediate on/off setting. Required uses the browser’s validation. Provide visible error guidance and do not rely on color alone.

API reference

Import { Checkbox, type CheckboxProps } from @/components/ui/yads-checkbox. Props use Radix Checkbox Root except asChild, children and dangerouslySetInnerHTML, which are intentionally unsupported: Checkbox owns its semantic button root and decorative indicator. The ref targets that button. Place labels and descriptions alongside or around Checkbox, not inside it.

Checkbox props, types, defaults and behavior
PropTypeDefaultDescription
checkedboolean | 'indeterminate'Not setControlled state. Pair with onCheckedChange; derive mixed state from child selections.
defaultCheckedboolean | 'indeterminate'falseInitial uncontrolled state, restored by native form reset. Do not switch between controlled and uncontrolled.
onCheckedChange(checked: boolean | 'indeterminate') => voidNot setCalled on user state changes. Activating an indeterminate control produces true.
disabledbooleanfalsePrevents activation, skips Tab and excludes the value from form submission.
requiredbooleanfalseRequires a checked value during native form validation. Mixed is not checked.
name / valuestring / stringNot set / "on"The enabled, checked form value. Unchecked and indeterminate controls do not submit.
formstringNot setAssociates the internal input with a form by id for submission. External-form reset is not guaranteed; see the limitation below.
id / aria-*Native attributesNot setUse id with a native label htmlFor; aria-describedby associates supporting text.
className / stylestring / React.CSSPropertiesNot setAdditional styling on the root. State is exposed through data-state.
refReact.Ref<HTMLButtonElement>Not setForwarded to the Radix button root, not its internal form input. Supports focus().

Native attributes and forms

Root button attributes, data-*, aria-*, style and event handlers are forwarded. Radix owns type="button", role, checked semantics and Space behavior; use onCheckedChange rather than input onChange. In a form, Radix renders an internal input for validation, form events and name/value submission. The root itself is not a native input; the ref points to a button. Children are reserved for the decorative indicator; place labels and descriptions outside Checkbox.

When nested inside a form, uncontrolled native reset restores the initial defaultChecked. For controlled state, handle the form’s onReset and restore application state yourself. Mixed is neither checked nor submitted. Disabled checked values are excluded from FormData.

External form limitation: in the tested Radix Checkbox 1.4.1, an explicit form id associates the internal input for submission, but native reset does not restore an uncontrolled root outside that form. Prefer nesting Checkbox inside the form, as in the example; otherwise control checked and restore it from the form’s onReset. This wrapper does not patch that upstream behavior.

Styling and playground defaults

The root exposes data-state="checked", "unchecked" or "indeterminate", and data-disabled when disabled. The scoped stylesheet includes light colors and a dark palette under a .dark ancestor, independent of host theme variables. Reset playground restores unchecked and enabled. Customization is ordinary CSS, not a variant or size prop.