Checkbox Group
---import { Checkbox } from "@/components/starwind/checkbox";import { CheckboxGroup } from "@/components/starwind/checkbox-group";---
<CheckboxGroup defaultValue={["email"]} aria-label="Notification channels"> <Checkbox name="notifications" value="email" label="Email" /> <Checkbox name="notifications" value="sms" label="SMS" /> <Checkbox name="notifications" value="push" label="Push" /></CheckboxGroup>import { Checkbox } from "@/components/starwind/checkbox";import { CheckboxGroup } from "@/components/starwind/checkbox-group";
export function Example() { return ( <CheckboxGroup defaultValue={["email"]} aria-label="Notification channels"> <Checkbox name="notifications" value="email" label="Email" /> <Checkbox name="notifications" value="sms" label="SMS" /> <Checkbox name="notifications" value="push" label="Push" /> </CheckboxGroup> );}<script setup lang="ts">import { Checkbox } from "@/components/starwind/checkbox";import { CheckboxGroup } from "@/components/starwind/checkbox-group";</script>
<template> <CheckboxGroup :defaultValue="['email']" aria-label="Notification channels"> <Checkbox name="notifications" value="email" label="Email" /> <Checkbox name="notifications" value="sms" label="SMS" /> <Checkbox name="notifications" value="push" label="Push" /> </CheckboxGroup></template><script lang="ts"> import { Checkbox } from "@/components/starwind/checkbox"; import { CheckboxGroup } from "@/components/starwind/checkbox-group";</script>
<CheckboxGroup defaultValue={["email"]} aria-label="Notification channels"> <Checkbox id="docs-checkbox-group-notifications-email" name="notifications" value="email" label="Email" /> <Checkbox id="docs-checkbox-group-notifications-sms" name="notifications" value="sms" label="SMS" /> <Checkbox id="docs-checkbox-group-notifications-push" name="notifications" value="push" label="Push" /></CheckboxGroup>Installation
pnpx starwind@latest add checkbox-group --framework astronpx starwind@latest add checkbox-group --framework astroyarn dlx starwind@latest add checkbox-group --framework astropnpx starwind@latest add checkbox-group --framework reactnpx starwind@latest add checkbox-group --framework reactyarn dlx starwind@latest add checkbox-group --framework reactpnpx starwind@latest add checkbox-group --framework vuenpx starwind@latest add checkbox-group --framework vueyarn dlx starwind@latest add checkbox-group --framework vuepnpx starwind@latest add checkbox-group --framework sveltenpx starwind@latest add checkbox-group --framework svelteyarn dlx starwind@latest add checkbox-group --framework svelteUsage
Use disabled on the group to disable every child without repeating the prop.
---import { Checkbox } from "@/components/starwind/checkbox";import { CheckboxGroup } from "@/components/starwind/checkbox-group";---
<CheckboxGroup disabled aria-label="Unavailable channels"> <Checkbox value="email" label="Email" /> <Checkbox value="sms" label="SMS" /></CheckboxGroup>import { Checkbox } from "@/components/starwind/checkbox";import { CheckboxGroup } from "@/components/starwind/checkbox-group";
export function Example() { return ( <> <CheckboxGroup disabled aria-label="Unavailable channels"> <Checkbox value="email" label="Email" /> <Checkbox value="sms" label="SMS" /> </CheckboxGroup> </> );}<script setup lang="ts">import { Checkbox } from "@/components/starwind/checkbox";import { CheckboxGroup } from "@/components/starwind/checkbox-group";</script>
<template> <CheckboxGroup disabled aria-label="Unavailable channels"> <Checkbox value="email" label="Email" /> <Checkbox value="sms" label="SMS" /> </CheckboxGroup></template><script lang="ts"> import { Checkbox } from "@/components/starwind/checkbox"; import { CheckboxGroup } from "@/components/starwind/checkbox-group";</script>
<CheckboxGroup disabled aria-label="Unavailable channels"> <Checkbox value="email" label="Email" /> <Checkbox value="sms" label="SMS" /></CheckboxGroup>API Reference
Styled Component API
These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.
Checkbox Group
Inherits div attributes. Omits `defaultValue` and `onChange`.
Contains the following additional props:
defaultValue string[] —
- Description
- Sets the initial value when the component is uncontrolled.
- Classification
- Primitive override
- Primitive prop
- checkbox-group.Root.defaultValue
Primitive And Runtime API
Use these references when you need the lower-level behavior APIs behind Checkbox Group.
Primitive API
Runtime API
- Checkbox Group primitive
createCheckboxGroupfrom@starwind-ui/runtime/checkbox-group
Changelog
View version history v1.1.1 5 releases
v1.1.1
- In Vue, this component now needs Vue 3.5.21 or newer.
- Maintenance release for the component files that the CLI copies into your project. Only internal code changed, such as unused code and import order. Behavior stays the same.
v1.1.0
- In Svelte, a defined
valuethat you pass when CheckboxGroup mounts now stays under your control, as in React and Vue. To change it, usebind:or update your state in the change callback. A form reset keeps it. If you passundefinedat mount, CheckboxGroup keeps its own state. - In Svelte, CheckboxGroup now follows
push()andsplice()on a$statearray that you pass asvalue.
v1.0.2
- React and Vue Checkbox Group now use the group value to select their children, including when a child has its own
checkedordefaultCheckedvalue. - Reduced the JavaScript loaded by Checkbox Group when it is used without Field.
v1.0.1
- In React, you can cancel a change before it applies. The component then keeps its previous state, and it shows only the changes that apply.
v1.0.0
- Added Checkbox Group. It gets its behavior from Starwind Runtime. The group controls its checkboxes and sends their values with the native form.
- See the Checkbox Group Primitive for the unstyled parts and the behavior API.