Checkbox Group
Checkbox groups let users select any number of related options. Use them when choices are independent and more than one can be selected.
Try it
Usage
The live value property is always a string[] ([] when nothing is selected). The HTML attribute is those tokens as a comma-separated string. JSX may pass a string or an array; a string is parsed as CSV. See Events for how the group forwards checkbox changes. Set name on the group. RuiField registers the group under that name and each checked, enabled checkbox submits one native FormData entry under it.
import { RuiCheckbox } from '@ecopages/radiant-ui/checkbox';
import { RuiCheckboxGroup, RuiCheckboxGroupControl } from '@ecopages/radiant-ui/checkbox-group';
import { RuiField } from '@ecopages/radiant-ui/field';
import { RuiLabel } from '@ecopages/radiant-ui/label';
<RuiField>
<RuiLabel>Topics</RuiLabel>
<RuiCheckboxGroup value={['news', 'travel']} name="topics" label="Topics">
<RuiCheckboxGroupControl>
<RuiCheckbox name="topics" value="news">News</RuiCheckbox>
<RuiCheckbox name="topics" value="travel">Travel</RuiCheckbox>
</RuiCheckboxGroupControl>
</RuiCheckboxGroup>
</RuiField>Custom markup
<rui-checkbox-group> coordinates any light-DOM tree that matches its query contract. The Rui* helpers stamp these targets; they are not required.
import '@ecopages/radiant-ui/checkbox-group';
import '@ecopages/radiant-ui/checkbox';
<rui-checkbox-group value="news,travel" name="topics" label="Topics">
<div data-checkbox-group-root role="group" class="rui-checkbox-group">
<rui-checkbox name="topics" value="news">News</rui-checkbox>
<rui-checkbox name="topics" value="travel">Travel</rui-checkbox>
</div>
</rui-checkbox-group>The group owns name, checked and disabled on its checkbox children in server markup and after connect, including a checkbox inserted later. A disabled option is left out of the form data and of the values a RuiForm submits, though it can stay in value.
Independent choices
Use checkbox groups when users may select multiple related options. For mutually exclusive choices, use a radio group instead. For a single on/off toggle, use a checkbox.
Theming
Checkbox group layout uses the group surface only; checkbox chrome comes from RuiCheckbox:
| Part | CSS roles |
|---|---|
Group (.rui-checkbox-group) | gap-inline; horizontal layout via data-orientation |
| Checkbox rows | See Checkbox theming |
API
RuiCheckboxGroup is a custom element (<rui-checkbox-group>). Compose its options with RuiCheckboxGroupControl and RuiCheckbox, or use the convenience options prop.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
value | string | omitted | Comma-separated selected tokens. Empty selection removes the attribute. The JS property is string[]. The server markup checks the checkboxes whose value the group holds. |
name | string | '' | Shared name for field registration and submission by the group’s checkboxes. |
label | string | '' | Accessible name when no visible legend is composed in the view. |
disabled | boolean | false | Disables every checkbox in the group. |
orientation | 'horizontal' | 'vertical' | 'vertical' | Layout axis for checkbox items. |
Light-DOM contract
| Target | Required | Host writes | Author owns |
|---|---|---|---|
[data-checkbox-group-root] | yes | aria-label, aria-disabled, data-orientation | the group node |
rui-checkbox | yes (per option) | name, checked, disabled | value, data-disabled |
Do not set checked or disabled on checkboxes. Nested hosts: rui-checkbox.
Events
| Event | Detail | Description |
|---|---|---|
input | none | The native inner checkbox <input> event, bubbling through the host. Read host.value. |
change | none | The native inner checkbox <input> event on commit, bubbling through the host. Read host.value. |
rui-checkbox-group dispatches no event of its own: the input and change of its native inner <input> bubble through the host, which syncs its state in a capture listener first, so a listener on the host or an ancestor reads fresh host.value. Act only when event.target is the control's member input. A programmatic write dispatches nothing.
Props
| Prop | Type | Description |
|---|---|---|
options | RuiCheckboxOption[] | { value, label, disabled? } entries rendered by the view. |
value | string | string[] | Selected tokens. A string is parsed as CSV; the host stores string[]. |
View helpers
| Component | Target stamped | Notes |
|---|---|---|
RuiCheckboxGroup | <rui-checkbox-group> | Accepts options or children. |
RuiCheckboxGroupControl | [data-checkbox-group-root] | role="group" container. |
RuiCheckbox | rui-checkbox | One per option; see Checkbox. |
CSS classes
| Class | Description |
|---|---|
.rui-checkbox-group | Group surface (role="group"). |
Accessibility
- The group exposes
role="group"with an accessible name fromlabelor an associatedRuiLabel. - Each option is a native checkbox with Space-to-toggle.
- For required multi-select fields, validate through
RuiFieldrules rather than per-checkboxrequired.