

<InteractiveDemo
  name="checkbox-group"
  controls="[
  {
    type: 'string',
    name: 'label',
    defaultValue: 'Select frameworks',
  },
  {
    type: 'boolean',
    name: 'isDisabled',
    defaultValue: false,
  },
  {
    type: 'boolean',
    name: 'isReadOnly',
    defaultValue: false,
  },
  {
    type: 'boolean',
    name: 'isInvalid',
    defaultValue: false,
  },
]"
/>

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/checkbox-group
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/checkbox-group
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/checkbox-group
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun x shadcn@latest add @dotui/checkbox-group
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

Use `CheckboxGroup` to allow users to select multiple items from a list of options.

```tsx
import { CheckboxGroup } from '@/components/ui/checkbox-group'
import { Checkbox, CheckboxControl } from '@/components/ui/checkbox'
import { FieldGroup, Label } from '@/components/ui/field'
```

```tsx
<CheckboxGroup defaultValue={['nextjs']}>
  <Label>React frameworks</Label>
  <FieldGroup>
    <Checkbox value="nextjs">
      <CheckboxControl />
      <Label>Next.js</Label>
    </Checkbox>
    <Checkbox value="remix">
      <CheckboxControl />
      <Label>Remix</Label>
    </Checkbox>
  </FieldGroup>
</CheckboxGroup>
```

## Selection [#selection]

Use `defaultValue` for uncontrolled checkbox groups, or `value` and `onChange` for controlled checkbox groups.

```tsx
<CheckboxGroup defaultValue={['nextjs']}>{/* ... */}</CheckboxGroup>
```

```tsx
const [frameworks, setFrameworks] = useState<string[]>(['nextjs'])

;<CheckboxGroup value={frameworks} onChange={setFrameworks}>
  {/* ... */}
</CheckboxGroup>
```

## Examples [#examples]

<Examples className="lg:grid-cols-3">
  <Example name="checkbox-group/demos/default" title="Default" />

  <Example name="checkbox-group/demos/description" title="With Description" />

  <Example name="checkbox-group/demos/error-message" title="Invalid" />

  <Example name="checkbox-group/demos/disabled" title="Disabled" />

  <Example name="checkbox-group/demos/read-only" title="ReadOnly" />

  <Example name="checkbox-group/demos/required" title="Required" />

  <Example name="checkbox-group/demos/cards" title="Cards" className="lg:col-span-3" />
</Examples>

## API Reference [#api-reference]

### CheckboxGroup [#checkboxgroup]

<Reference name="checkbox-group" />

### Checkbox [#checkbox]

<Reference name="checkbox" />
