# CheckboxGroup Primitive

CheckboxGroup is a Starwind Runtime primitive in the controlled-value-group contract family.
## Anatomy
### Astro
Use the Astro primitive adapter to render CheckboxGroup anatomy with the Runtime wiring included.
```astro
---
import { CheckboxGroup } from "@starwind-ui/astro/checkbox-group";
---

<CheckboxGroup.Root />
```

### React
Use the React primitive adapter when CheckboxGroup state participates in React rendering.
```tsx
import { CheckboxGroup } from "@starwind-ui/react/checkbox-group";

export function Example() {
  return (
    <CheckboxGroup.Root />
  );
}
```

### HTML
Render the CheckboxGroup data-sw-* contract yourself, then initialize createCheckboxGroup.
```html
<div data-sw-checkbox-group role="group"></div>

<script type="module">
  import { createCheckboxGroup } from "@starwind-ui/runtime/checkbox-group";

  const root = document.querySelector("[data-sw-checkbox-group]");
  if (root) {
    createCheckboxGroup(root);
  }
</script>
```
## API Reference
### Root
The main element that owns the CheckboxGroup Runtime instance.
| Fact | Value |
| --- | --- |
| Default element | `div` |
| Discovery hook | `data-sw-checkbox-group` |
| Role | `group` |
#### Props
| Prop | Type | Default | Kind | Description |
| --- | --- | --- | --- | --- |
| value | `CheckboxGroupValue` | - | control | Controls the current CheckboxGroup value. |
| defaultValue | `CheckboxGroupValue` | - | control | Sets the initial CheckboxGroup value for uncontrolled usage. |
| disabled | `boolean` | false | option | Disables the Root part. |
| onValueChange | `(value: CheckboxGroupValue, details: CheckboxGroupValueChangeDetails) => void` | - | callback | Runs when the CheckboxGroup value changes. |
#### Data Attributes
| Attribute | Source | Value | Description |
| --- | --- | --- | --- |
| `data-sw-checkbox-group` | runtime | - | Marks the Root part so Starwind Runtime can find it. |
| `data-default-value` | prop | - | Reflects the default value prop on the Root part. |
| `data-disabled` | prop | - | Reflects the disabled prop on the Root part. |
| `data-value` | state | - | Reflects the value state on the Root part. |
#### State
| State | Value Type | Controlled Prop | Default Prop | Initial Attribute | Runtime Getter | Runtime Setter | Description | State Control Support |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| value | `CheckboxGroupValue` | value | defaultValue | `data-default-value` | `getValue` | `setValue` | Tracks the current CheckboxGroup value. | React supports controlled and default state with value and defaultValue props. Runtime/HTML reads initial state from data-default-value, emits starwind:value-change, and updates with setValue. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state. |
#### Events
| Event | Callback | DOM Event | Value | Details | Timing | Cancelable | Description |
| --- | --- | --- | --- | --- | --- | --- | --- |
| valueChange | onValueChange | starwind:value-change | value: `CheckboxGroupValue` | CheckboxGroupValueChangeDetails | before-state-commit | Yes | Fires when the value changes for CheckboxGroup. |
#### Runtime Setters
| Method | Target | Options | Suppresses Emit | Description |
| --- | --- | --- | --- | --- |
| `setValue` | state: value | emit: false | Yes | Updates the current CheckboxGroup value from Runtime code. |
| `setDisabled` | prop: disabled | - | No | Updates whether CheckboxGroup is disabled from Runtime code. |
#### Refs
| Part | Public |
| --- | --- |
| root | Yes |
#### Context
| Name | Direction | Values |
| --- | --- | --- |
| checkbox-group | provides | disabled, value |
#### Initial Markup
| Attributes | Reason |
| --- | --- |
| `data-sw-checkbox-group`, `role`, `data-default-value`, `data-disabled`, `data-value` | The checkbox group needs initial selection and disabled state for child checkbox styling before hydration. |
## Runtime API
| Fact | Value |
| --- | --- |
| Factory | [`createCheckboxGroup`](/docs/runtime/#create-checkbox-group) |
| Import | `@starwind-ui/runtime/checkbox-group` |
| Root part | root |
| Option props | defaultValue, disabled, value |
| Option lifecycles | - |
## Related Styled Components
| Component | Relationship |
| --- | --- |
| [Checkbox Group](/docs/components/checkbox-group/) | Direct Primitive |
## Exports
| Group | Import | Exports |
| --- | --- | --- |
| Runtime | `@starwind-ui/runtime/checkbox-group` | `createCheckboxGroup` |
| Astro Primitive | `@starwind-ui/astro/checkbox-group` | `CheckboxGroup`, `CheckboxGroupRoot` |
| React Primitive | `@starwind-ui/react/checkbox-group` | `CheckboxGroup`, `CheckboxGroupRoot` |
## Canonical Names
| Kind | Name |
| --- | --- |
| namespace | `CheckboxGroup` |
| runtime-factory | `createCheckboxGroup` |
| part | `CheckboxGroup.Root` |