Inputs
CheckboxGroup A compound component for managing a group of related checkboxes with shared state.
npm pnpm yarn bun
npm install @morphos/inputs
import { CheckboxGroup, CheckboxGroupItem } from '@morphos/inputs'
Component Description CheckboxGroupRoot container that manages group state, rendered with role="group" CheckboxGroupItemIndividual checkbox item within the group
@ Component ()
class MyComponent extends StatefulComponent {
@ State () group = new CheckboxGroup ({ defaultValue: [ 'notifications' ], orientation: 'vertical' })
render () {
return (
< CheckboxGroup class = "morphos-checkbox-group" orientation = "vertical" aria-label = "Notification channels" >
< CheckboxGroupItem class = "morphos-checkbox-group-item" group = { this .group} value = "notifications" >
Email notifications
</ CheckboxGroupItem >
< CheckboxGroupItem class = "morphos-checkbox-group-item" group = { this .group} value = "sms" >
SMS notifications
</ CheckboxGroupItem >
< CheckboxGroupItem class = "morphos-checkbox-group-item" group = { this .group} value = "push" >
Push notifications
</ CheckboxGroupItem >
</ CheckboxGroup >
)
}
}
The group prop on each CheckboxGroupItem must be the same CheckboxGroup instance backing the rendered <CheckboxGroup> root — CheckboxGroupItem reads group.isChecked(value) and calls group.toggle(value) directly on it.
@ Component ()
class MyComponent extends StatefulComponent {
@ State () group = new CheckboxGroup ({})
@ State () selected = [ 'sms' ]
render () {
return (
< CheckboxGroup
class = "morphos-checkbox-group"
value = {() => this .selected}
onValueChange = {( values ) => ( this .selected = values)}
aria-label = "Notification preferences"
>
< CheckboxGroupItem class = "morphos-checkbox-group-item" group = { this .group} value = "email" >
Email
</ CheckboxGroupItem >
< CheckboxGroupItem class = "morphos-checkbox-group-item" group = { this .group} value = "sms" >
SMS
</ CheckboxGroupItem >
</ CheckboxGroup >
)
}
}
@ Component ()
class MyComponent extends StatefulComponent {
@ State () group = new CheckboxGroup ({ disabled: true })
render () {
return (
< fieldset >
< legend >Disabled options</ legend >
< CheckboxGroup class = "morphos-checkbox-group" disabled aria-label = "Disabled options" >
< CheckboxGroupItem class = "morphos-checkbox-group-item" group = { this .group} value = "a" >Option A</ CheckboxGroupItem >
< CheckboxGroupItem class = "morphos-checkbox-group-item" group = { this .group} value = "b" >Option B</ CheckboxGroupItem >
</ CheckboxGroup >
</ fieldset >
)
}
}
Prop Type Default Description valuestring[]— Controlled array of checked values defaultValuestring[][]Uncontrolled initial checked values disabledbooleanfalseDisables all items in the group requiredbooleanfalseMarks the group as required (aria-required) namestring— Name shared by every item's <input> in the group orientation"vertical" | "horizontal""vertical"Sets aria-orientation and data-orientation onValueChange(value: string[]) => void— Fires when the selected values change classstring— Additional CSS classes idstring— HTML id attribute childrenChildren— The CheckboxGroupItem items aria-labelstring— Accessible label for the group aria-labelledbystring— ID of an element that labels the group aria-describedbystring— ID of an element that describes the group
Method Description isChecked(value: string)Returns whether value is currently in the group's checked values. toggle(value: string)Adds or removes value from the group's checked values. Emits onValueChange with the new array.
Prop Type Default Description groupCheckboxGroup— The parent CheckboxGroup instance (required) valuestring— The value this item represents (required) disabledboolean— Overrides the group's disabled for this item only childrenChildren— Label content rendered inside the <label>, beside the checkbox classstring— Additional CSS classes on the <label> idstring— HTML id attribute on the <label> aria-labelstring— Accessible label for this item's <input> aria-labelledbystring— ID of an element that labels this item's <input>
Attribute Element When present data-disabledGroup root disabled is truedata-orientationGroup root Always — value is "vertical" or "horizontal" data-checkedItem <label> Item's value is in the group's current value array data-disabledItem <label> Group's disabled or the item's own disabled is true
CheckboxGroup renders a <div role="group"> with aria-orientation, aria-required, and aria-disabled. Each CheckboxGroupItem renders <label><input type="checkbox" />children</label>, so the label click target covers the checkbox and every item shares the group's required state and name. Wrap the group in a <fieldset> with a <legend> for screen readers to announce the group context — CheckboxGroup does not render its own <fieldset>.
Use the Fieldset component from @morphos/inputs as the container when you need a semantic group with a visible legend and proper disabled propagation at the HTML level.
.morphos-checkbox-group [ data-orientation = "horizontal" ] {
flex-direction : row ;
gap : var ( --morphos-space-4 );
}
.morphos-checkbox-group-item input [ type = "checkbox" ] :checked {
background : var ( --morphos-color-accent );
border-color : var ( --morphos-color-accent );
}
.morphos-checkbox-group-item [ data-disabled ] {
opacity : 0.5 ;
cursor : not-allowed ;
}