Getting started

Actions

Forms

Layout

Navigation

Overlays

Feedback

Data display

Controllers

Helpers

Recipes

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:

PartCSS roles
Group (.rui-checkbox-group)gap-inline; horizontal layout via data-orientation
Checkbox rowsSee 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

AttributeTypeDefaultDescription
valuestringomittedComma-separated selected tokens. Empty selection removes the attribute. The JS property is string[]. The server markup checks the checkboxes whose value the group holds.
namestring''Shared name for field registration and submission by the group’s checkboxes.
labelstring''Accessible name when no visible legend is composed in the view.
disabledbooleanfalseDisables every checkbox in the group.
orientation'horizontal' | 'vertical''vertical'Layout axis for checkbox items.

Light-DOM contract

TargetRequiredHost writesAuthor owns
[data-checkbox-group-root]yesaria-label, aria-disabled, data-orientationthe group node
rui-checkboxyes (per option)name, checked, disabledvalue, data-disabled

Do not set checked or disabled on checkboxes. Nested hosts: rui-checkbox.

Events

EventDetailDescription
inputnoneThe native inner checkbox <input> event, bubbling through the host. Read host.value.
changenoneThe 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

PropTypeDescription
optionsRuiCheckboxOption[]{ value, label, disabled? } entries rendered by the view.
valuestring | string[]Selected tokens. A string is parsed as CSV; the host stores string[].

View helpers

ComponentTarget stampedNotes
RuiCheckboxGroup<rui-checkbox-group>Accepts options or children.
RuiCheckboxGroupControl[data-checkbox-group-root]role="group" container.
RuiCheckboxrui-checkboxOne per option; see Checkbox.

CSS classes

ClassDescription
.rui-checkbox-groupGroup surface (role="group").

Accessibility

  • The group exposes role="group" with an accessible name from label or an associated RuiLabel.
  • Each option is a native checkbox with Space-to-toggle.
  • For required multi-select fields, validate through RuiField rules rather than per-checkbox required.