# Checkbox Group Primitive

Checkbox Group is a Starwind Runtime primitive in the controlled-value-group contract family.
Astro and React share one semantic component API. React coordinates reactive state through controlled and default props plus callbacks. Astro renders initial state and coordinates later changes through DOM events and Runtime methods. Raw HTML uses Runtime attributes, DOM events, and imperative methods.
## 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>
```

### Vue
Use the Vue 3.5 beta adapter to render CheckboxGroup anatomy.
```vue
<script setup lang="ts">
import CheckboxGroup from "@starwind-ui/vue/checkbox-group";
</script>

<template>
  <CheckboxGroup.Root />
</template>
```
## API Reference
### Root
The main element that owns the Checkbox Group Runtime instance.
| Fact | Value |
| --- | --- |
| Default element | `div` |
| Discovery hook | `data-sw-checkbox-group` |
| Role | `group` |
#### Props
| Prop | Type | Default | Kind | Description | Framework Behavior |
| --- | --- | --- | --- | --- | --- |
| value | `CheckboxGroupValue` | - | control | Controls the current Checkbox Group value. | **React:** Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.<br>**Astro:** Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.<br>**Runtime / HTML:** Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates. |
| defaultValue | `CheckboxGroupValue` | - | control | Sets the initial Checkbox Group value for uncontrolled usage. | **React:** Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.<br>**Astro:** Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.<br>**Runtime / HTML:** Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates. |
| disabled | `boolean` | false | option | Disables the Root part. | - |
| onValueChange | `(value: CheckboxGroupValue, details: CheckboxGroupValueChangeDetails) => void` | - | callback | Runs when the Checkbox Group value changes. | **React:** Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.<br>**Astro:** Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.<br>**Runtime / HTML:** Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates. |
#### 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 Checkbox Group value. | **React:** Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.<br>**Astro:** Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.<br>**Runtime / HTML:** Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates. |
#### Events
| Event | Callback | DOM Event | Value | Details | Timing | Cancelable | Description | Cancellation Sequence |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| valueChange | onValueChange | starwind:value-change | value: `CheckboxGroupValue` | CheckboxGroupValueChangeDetails | before-state-commit | Yes | Fires when the value changes for Checkbox Group. | 1. Check internal eligibility and intent.<br>2. Create one details object for the proposal.<br>3. Call the Runtime callback with the details object when the controller exposes one.<br>4. Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.<br>5. Read details.isCanceled, including cancellation caused by preventDefault().<br>6. Apply the accepted state.<br>7. Notify Runtime subscribers and other accepted-only observers. |
#### Runtime Setters
| Method | Target | Options | Suppresses Emit | Description |
| --- | --- | --- | --- | --- |
| `setValue` | state: value | emit: false | Yes | Updates the current Checkbox Group value from Runtime code. |
| `setDisabled` | prop: disabled | - | No | Updates whether Checkbox Group 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` |
## Changelog
### v1.0.0
- Promoted this Primitive's vendoring version to the stable 1.0.0 baseline. Its existing API and Runtime behavior carry forward from the previous release.
### v0.1.1
- Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
- Kept generated React state-change callbacks and DOM events cancelable until the Runtime accepts the proposed state, then synchronized rendered state.
### v0.1.0
- Introduced grouped checkbox value ownership, shared disabled state, and form participation.