Checkbox group
Checkboxes grouped into one form control with a value array, a group label and an at-least-one rule.
c2-checkbox-group turns several c2-checkbox options into one form-associated control, the multi-select counterpart of c2-radio-group. Its value is the array of checked option values in document order; its name submits each of them to FormData; disabled disables every option while keeping the ones disabled on their own; and required means at least one option is checked. Each option keeps its native behaviour and stays its own tab stop, so Tab moves between options and Space toggles them. Options can sit anywhere inside the group, including in wrapper elements.
Import
import '@c2n/components/checkbox'Importing @c2n/components/checkbox registers both c2-checkbox-group and c2-checkbox. For the group alone, import '@c2n/components/checkbox/checkbox-group' registers it and its options.
Usage
Set the group’s value to check options from code: an array from script (group.value = ['email', 'sms']) or ;-separated values in markup (value="email;sms"). Without a value, options written with checked are adopted as the starting value. Listen for change on the group (detail.value is the new array) or input; the options’ own events stop at the group, so a listener above it hears exactly one of each per toggle. Neither fires for programmatic changes.
Give the group a name and every checked value is appended to FormData(form) under it; leave the options themselves unnamed. required, fieldset disabling, form.reset(), checkValidity(), reportValidity() and setCustomValidity() follow the native form contract. The label slot names the group for assistive technology (aria-label works too), and the text inside each c2-checkbox labels that option: clicking it toggles the box.
Theme the options through the --c2-checkbox__* variables (set them on the group and every option inherits them) and the group heading and spacing through --c2-checkbox-group__*; --c2-checkbox-group--align-items: stretch lets card-style options fill the width.