Skip to content
Thrum

Checkbox group

A named set of checkboxes that share one value, the list of ticked options. A select-all box ticks and clears them together and shows a dash while only some are ticked. For one choice out of the set use the radio group; for options that need a description each, use choice cards.

Install

npx shadcn@latest add https://thrumui.dev/r/checkbox-group.json

Adds components/ui/checkbox-group.tsx and installs @base-ui/react@1.9.0. Nothing else in your project changes.

import { CheckboxGroup } from "@/components/ui/checkbox-group";

Props

PropTypeDefaultDescription
CheckboxGroup: valuestring[]–The values of the ticked options, when the parent holds them. Use it with onValueChange.
CheckboxGroup: defaultValuestring[]Default []The options ticked at first, when the group holds the list itself.
CheckboxGroup: onValueChange(value: string[]) => void–Called with the new list when an option, or the select-all box, changes.
CheckboxGroup: allValuesstring[]–The value of every option. Needed for the select-all box, which compares the ticked list with it.
CheckboxGroup: disabledbooleanDefault falseEvery box in the group is dimmed and cannot be changed.
CheckboxGroup: orientation"vertical" | "horizontal"Default "vertical"vertical stacks the options 8 pixels apart. horizontal sets them in a row that wraps.
CheckboxGroup: classNamestring–Extra classes for the group, merged last. Set a width here.
CheckboxGroupLabelComponentProps<"div">–The group's visible name. The group points at it with aria-labelledby by itself.
CheckboxGroupItem: valuestring–The option's name in the group's list. Leave it out on the select-all box.
CheckboxGroupItem: parentbooleanDefault falseMakes this the select-all box: ticked when every option is, a dash when some are, and a press ticks or clears them all.
CheckboxGroupItem: disabledbooleanDefault falseThis option is dimmed and keeps its state. The select-all box leaves it as it is.
CheckboxGroupItem: size"md" | "lg"Default "md"md is a 16 pixel box, lg is 20 pixels.
CheckboxGroupItem: soundbooleanDefault truePlay a pair of clicks when this box changes, if the visitor has sound on.
CheckboxGroupItem: childrenReactNode–The option's text. It sits in a label with the box, so a press on it changes the box.
CheckboxGroupItem: ...propsCheckboxProps–Every other checkbox prop: name, required, readOnly, aria-invalid.

Motion and sound

Motion

  • Each box changes colour over 150 ms while its tick or dash fades in and grows from half size.
  • The select-all box swaps tick and dash at once when the count changes.
  • Reduced motion: every box changes at once.

Sound

  • Two rising clicks when a box is ticked, two falling clicks when it is cleared.
  • The select-all box makes one pair for the whole set, not one for each option.

Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works

Accessibility

  • The group has the group role and is named by CheckboxGroupLabel, or by an aria-label when there is no visible label.
  • Each option follows the WAI-ARIA checkbox pattern and is named by its own label text.
  • The select-all box reports aria-checked mixed while some options are ticked, and lists the boxes it controls in aria-controls.
  • Tick, dash and empty box differ in shape, so the state never rests on colour.
  • Long labels wrap beside their box. Nothing overflows at 160 pixels wide.
KeysAction
TabMove to the next box. Every box is its own tab stop; disabled ones are skipped.
SpaceTick or clear the focused box. On the select-all box: tick every option, then clear them, then bring back the earlier partial choice.

Source

components/ui/checkbox-group.tsx
"use client";

import { createContext, useContext, useId, type ComponentProps } from "react";
import { CheckboxGroup as CheckboxGroupPrimitive } from "@base-ui/react/checkbox-group";

import { cn } from "@/lib/utils";
import { Checkbox, type CheckboxProps } from "@/components/ui/checkbox";

/** The id of the group's label, so the label part and the group find each other. */
const LabelId = createContext<string | undefined>(undefined);

export type CheckboxGroupProps = CheckboxGroupPrimitive.Props & {
  /** `vertical` stacks the options, `horizontal` sets them in a row that wraps. */
  orientation?: "vertical" | "horizontal";
};

/**
 * A set of checkboxes that share one value: the list of ticked names. Each `CheckboxGroupItem` with a `value` is one option.
 * An item with `parent` ticks and clears them all; it needs `allValues`. Name the group with `CheckboxGroupLabel` or an `aria-label`.
 */
export function CheckboxGroup({ orientation = "vertical", className, ...props }: CheckboxGroupProps) {
  const labelId = useId();
  return (
    <LabelId value={labelId}>
      <CheckboxGroupPrimitive
        data-slot="checkbox-group"
        data-orientation={orientation}
        // An `aria-label` names the group by itself; otherwise the label part does.
        aria-labelledby={props["aria-label"] ? undefined : labelId}
        className={cn("flex min-w-0 gap-2 text-sm", orientation === "horizontal" ? "flex-wrap items-start gap-x-4" : "flex-col items-start", className)}
        {...props}
      />
    </LabelId>
  );
}

/** The group's visible name. It is a `<div>`: every box is named by its own label. */
export function CheckboxGroupLabel({ className, ...props }: ComponentProps<"div">) {
  const id = useContext(LabelId);
  return <div data-slot="checkbox-group-label" id={id} className={cn("w-full font-medium", className)} {...props} />;
}

/** One option: a checkbox and its text in a `<label>`, so a press on the text changes the box too. */
export function CheckboxGroupItem({ size = "md", className, children, ...props }: CheckboxProps) {
  return (
    // A disabled option dims as a whole, so the box does not dim a second time.
    <label data-slot="checkbox-group-item" className={cn("flex min-w-0 cursor-pointer items-start gap-2 has-data-disabled:cursor-not-allowed has-data-disabled:opacity-50", className)}>
      {/* The 16 pixel box sits 2 pixels down, level with the first line of 14 pixel text. */}
      <Checkbox size={size} className={cn("data-disabled:opacity-100", size === "md" && "mt-0.5")} {...props} />
      <span className="min-w-0">{children}</span>
    </label>
  );
}

Files and dependencies

Adds
components/ui/checkbox-group.tsx
Packages
@base-ui/react@1.9.0
Brings along
Checkbox

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor