# Checkbox Group

> Coordinates shared selection state across multiple checkboxes, including automatic parent indeterminate sync and tree connectors.

Canonical URL: https://taut-ui.com/docs/components/checkbox-group

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

const channels = [
  { label: "Email digest", value: "email" },
  { label: "Slack alerts", value: "slack" },
  { label: "Webhook events", value: "webhook" },
];

export default function Particle() {
  return (
    <CheckboxGroup defaultValue={["email", "slack"]}>
      {channels.map((channel) => (
        <label
          className="inline-flex cursor-pointer select-none items-center gap-2.5 text-foreground text-sm leading-5"
          key={channel.value}
        >
          <Checkbox value={channel.value} />
          {channel.label}
        </label>
      ))}
    </CheckboxGroup>
  );
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/checkbox-group.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react
```

- Copy and paste the following code into your project.

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

import { CheckboxGroup as CheckboxGroupPrimitive } from "@base-ui/react/checkbox-group";
import type React from "react";
import { cn } from "@/lib/utils";

export type CheckboxGroupProps = CheckboxGroupPrimitive.Props;

export function CheckboxGroup({
  className,
  ...props
}: CheckboxGroupPrimitive.Props): React.ReactElement {
  return (
    <CheckboxGroupPrimitive
      className={cn(
        "relative flex flex-col items-start gap-2.5",
        "[&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])]:font-medium",
        "[&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:relative [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:ms-6",
        "[&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*:last-child]:before:rounded-bl-sm [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:pointer-events-none [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:absolute [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:-start-3.5 [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:-top-3 [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:h-5.5 [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:w-2.5 [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:border-border [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:border-s [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*]:before:border-b",
        "[&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*:not(:last-child)]:after:pointer-events-none [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*:not(:last-child)]:after:absolute [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*:not(:last-child)]:after:-start-3.5 [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*:not(:last-child)]:after:top-2.5 [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*:not(:last-child)]:after:bottom-0 [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*:not(:last-child)]:after:w-px [&>:is(label,[data-slot=label],[data-slot=field-label]):has([data-parent])~*:not(:last-child)]:after:bg-border",
        className,
      )}
      data-slot="checkbox-group"
      {...props}
    />
  );
}

export { CheckboxGroupPrimitive };
```

- Update the import paths to match your project setup.

## Usage [#usage]

```tsx
import { Checkbox } from "@/components/ui/checkbox"
import { CheckboxGroup } from "@/components/ui/checkbox-group"
```

```tsx
<CheckboxGroup defaultValue={["email"]}>
  <label className="inline-flex items-center gap-2.5 text-sm">
    <Checkbox value="email" />
    Email
  </label>
  <label className="inline-flex items-center gap-2.5 text-sm">
    <Checkbox value="slack" />
    Slack
  </label>
</CheckboxGroup>
```

## Examples [#examples]

### Nested Parent [#nested-parent]

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

const permissions = [
  { label: "Read repositories", value: "read" },
  { label: "Write deployments", value: "write" },
  { label: "Manage billing", value: "billing" },
];

export default function Particle() {
  return (
    <CheckboxGroup
      allValues={permissions.map((item) => item.value)}
      defaultValue={["read"]}
    >
      <label className="inline-flex cursor-pointer select-none items-center gap-2.5 text-foreground text-sm leading-5">
        <Checkbox parent />
        Workspace permissions
      </label>
      {permissions.map((permission) => (
        <label
          className="inline-flex cursor-pointer select-none items-center gap-2.5 text-foreground text-sm leading-5"
          key={permission.value}
        >
          <Checkbox value={permission.value} />
          {permission.label}
        </label>
      ))}
    </CheckboxGroup>
  );
}
```

## API Reference [#api-reference]

### CheckboxGroup [#checkboxgroup]

Wraps Base UI `CheckboxGroup`. When a child label contains `<Checkbox parent />`, sibling items are automatically indented with subtle tree connector lines.

| Prop            | Type                        | Default | Description                                        |
| --------------- | --------------------------- | ------- | -------------------------------------------------- |
| `value`         | `string[]`                  | -       | Controlled array of checked values                 |
| `defaultValue`  | `string[]`                  | `[]`    | Initial uncontrolled array of checked values       |
| `onValueChange` | `(value: string[]) => void` | -       | Called when the group selection changes            |
| `allValues`     | `string[]`                  | -       | Full list of values required when using `parent`   |
| `disabled`      | `boolean`                   | `false` | Disables all checkboxes inside the group           |
| `className`     | `string`                    | -       | Additional CSS classes                             |
