Prototyper UI

Checkbox Group

group of checkboxes with shared state and select-all support

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/checkbox-group.json
npx shadcn@latest add https://prototyper-ui.com/r/checkbox-group.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/checkbox-group.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/checkbox-group.json

This will add the following files to your project:

  • components/ui/checkbox-group.tsx

Usage

import { CheckboxGroup } from "@/components/ui/checkbox-group";
import {
  Checkbox,
  CheckboxControl,
  CheckboxIndicator,
} from "@/components/ui/checkbox";

<CheckboxGroup defaultValue={["option-1"]}>
  <Checkbox value="option-1">
    <CheckboxControl>
      <CheckboxIndicator />
    </CheckboxControl>
    Option 1
  </Checkbox>
  <Checkbox value="option-2">
    <CheckboxControl>
      <CheckboxIndicator />
    </CheckboxControl>
    Option 2
  </Checkbox>
</CheckboxGroup>;

Anatomy

<CheckboxGroup>
  <Checkbox>
    <CheckboxControl>
      <CheckboxIndicator />
    </CheckboxControl>
    {/* label text */}
  </Checkbox>
</CheckboxGroup>
Sub-componentdata-slotPurposeRequired
CheckboxGroupcheckbox-groupRoot container, manages group stateYes
CheckboxcheckboxIndividual checkbox (from checkbox component)Yes
CheckboxControlcheckbox-controlVisual box (from checkbox component)Yes
CheckboxIndicatorcheckbox-indicatorCheckmark icon (from checkbox component)Yes

Examples

Parent (Select All)

Loading...

Disabled

Loading...

Controlled

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the checkbox group:

Slot nameElement
checkbox-groupRoot container for all checkboxes

Customization Examples

/* Horizontal layout */
[data-slot="checkbox-group"] {
  @apply flex-row gap-4;
}
{
  /* Override layout via className */
}
<CheckboxGroup className="flex-row gap-6">{/* ... */}</CheckboxGroup>;

API Reference

CheckboxGroup

Root container that manages which checkboxes are checked.

Prop

Type

All Base UI CheckboxGroup props are forwarded via ...props.

Accessibility

Keyboard Interactions

KeyAction
SpaceToggles the focused checkbox
TabMoves focus between checkboxes

ARIA Attributes

  • CheckboxGroup renders with role="group".
  • Each Checkbox within renders with role="checkbox".
  • aria-checked is set to true, false, or mixed (for parent checkbox) based on state.
  • aria-disabled is set when the group or an individual checkbox is disabled.
  • The parent checkbox shows mixed state when some but not all children are checked.

On this page