Checkbox Group Primitive
Use Checkbox Group to let someone choose any number of options. The group collects the checked values and can disable its checkboxes together.
Email notifications
Anatomy
Use the Astro primitive adapter to render CheckboxGroup anatomy with the Runtime wiring included.
---import { CheckboxGroup } from "@starwind-ui/astro/checkbox-group";---
<CheckboxGroup.Root />Use the React primitive adapter when CheckboxGroup state participates in React rendering.
import { CheckboxGroup } from "@starwind-ui/react/checkbox-group";
export function Example() { return ( <CheckboxGroup.Root /> );}Use the Vue components to build CheckboxGroup.
<script setup lang="ts">import CheckboxGroup from "@starwind-ui/vue/checkbox-group";</script>
<template> <CheckboxGroup.Root /></template>Use the Svelte components to build CheckboxGroup.
<script lang="ts"> import { CheckboxGroup } from "@starwind-ui/svelte/checkbox-group";</script>
<CheckboxGroup.Root />Render the CheckboxGroup data-sw-* contract yourself, then initialize createCheckboxGroup.
<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>Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed package’s types for the available props and events. Plain HTML uses DOM events and Runtime methods.
API Reference
Root
The main element that owns the Checkbox Group Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-checkbox-group
- Role
- group
Props
value CheckboxGroupValue -
- Description
- Controls the current Checkbox Group value.
- Kind
- control
- Targets
- -
- Full type
- CheckboxGroupValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
defaultValue CheckboxGroupValue -
- Description
- Sets the initial Checkbox Group value for uncontrolled usage.
- Kind
- control
- Targets
- -
- Full type
- CheckboxGroupValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
disabled boolean false
- Description
- Disables the Root part.
- Kind
- option
- Targets
- -
- Full type
- boolean
onValueChange (value: CheckboxGroupValue, details: CheckboxGroupValueChangeDetails) => void -
- Description
- Runs when the Checkbox Group value changes.
- Kind
- callback
- Targets
- -
- Full type
- (value: CheckboxGroupValue, details: CheckboxGroupValueChangeDetails) => void
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Events
valueChange onValueChange value: CheckboxGroupValue
- Description
- Fires when the value changes for Checkbox Group.
- DOM event
- starwind:value-change
- Details type
- CheckboxGroupValueChangeDetails
- Timing
- before-state-commit
- Cancelable
- Yes
- Cancellation sequence
- Check internal eligibility and intent.
- Create one details object for the proposal.
- Call the Runtime callback with the details object when the controller exposes one.
- Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
- Read details.isCanceled, including cancellation caused by preventDefault().
- Apply the accepted state.
- Notify Runtime subscribers and other accepted-only observers.
State
value CheckboxGroupValue value / defaultValue
- Description
- Tracks the current Checkbox Group value.
- Initial attribute
- data-default-value
- Runtime getter
- getValue
- Runtime setter
- setValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Data Attributes
Runtime hooks
State
Metadata
Runtime API
- Factory
createCheckboxGroup- Import
@starwind-ui/runtime/checkbox-group- Root hook
- root
data-sw-checkbox-group - Option props
- defaultValue, disabled, value
Runtime Setters
Related Styled Components
Changelog
View version history v1.1.1 6 releases
v1.1.1
- In Vue, this component now needs Vue 3.5.21 or newer.
v1.1.0
- In Svelte, a defined `value` that you pass when CheckboxGroup mounts now stays under your control, as in React and Vue. To change it, use `bind:` or update your state in the change callback. A form reset keeps it. If you pass `undefined` at mount, CheckboxGroup keeps its own state. It also follows `push()` and `splice()` on a `$state` array.
v1.0.1
- React and Vue Checkbox Group now use the group value to select their children, including when a child has its own `checked` or `defaultChecked` value.
- Reduced the JavaScript loaded by Checkbox Group when it is used without Field.
- Reduced repeated JavaScript when Astro Checkbox Group is used with other Starwind components.
- Reduced JavaScript used by Vue Checkbox Group. Props and defaults stay the same.
v1.0.0
- This Primitive is now stable at version `1.0.0`. Its API and behavior stay the same as in the previous release.
v0.1.1
- The React Primitive files that the CLI copies into your project are now marked with `"use client"`, so they stay client components in React server frameworks.
- In React, you can cancel a change from its change callback or DOM event before it applies. React then shows only the changes that apply.
v0.1.0
- First release. Checkbox Group holds the value of its checkboxes, can disable all of them, and sends their values with the form.