Getting started

Actions

Forms

Layout

Navigation

Overlays

Feedback

Data display

Controllers

Helpers

Recipes

Checkbox

Checkboxes toggle independent options on or off. Use them when each choice is unrelated and more than one can be selected.

Try it

Usage

Wrap a checkbox in RuiField with RuiLabel for consistent spacing and error display. Bind checked for controlled state.

import { RuiCheckbox } from '@ecopages/radiant-ui/checkbox';
import { RuiField } from '@ecopages/radiant-ui/field';
import { RuiLabel } from '@ecopages/radiant-ui/label';

<RuiField>
  <RuiLabel>Email me product updates</RuiLabel>
  <RuiCheckbox name="newsletter" checked={subscribed} value="yes" />
</RuiField>

Custom markup

<rui-checkbox> coordinates any light-DOM tree that matches its query contract. The RuiCheckbox helper stamps these targets; it is not required.

import '@ecopages/radiant-ui/checkbox';

<rui-checkbox checked value="yes">
  <label class="rui-checkbox">
    <input
      type="checkbox"
      data-ref="input"
      data-rui-control
      data-rui-control-type="boolean"
      class="rui-checkbox__input"
    />
    <span class="rui-checkbox__control" aria-hidden="true"></span>
    <span class="rui-checkbox__label">Email me product updates</span>
  </label>
</rui-checkbox>

BEM classes are presentation-only. The host syncs checked, indeterminate, disabled, value, name, and aria-checked on [data-ref="input"].

Indeterminate selections

Set indeterminate when a parent checkbox represents a partially selected group. Clear indeterminate once the user makes an explicit choice.

For multiple related options as one form field, use a checkbox group. For mutually exclusive choices, use a radio group.

Wire through RuiField

Set name on the checkbox so it participates in RuiForm validation and submission.

Theming

Checkbox chrome maps to semantic surface roles, never Tailwind palette steps:

Part / stateCSS roles
Box (rui-checkbox__control)border, background, rounded-control
Checked boxprimary fill, on-primary check glyph
Indeterminate barprimary on background
Focusfocus-ring
Disabledopacity-disabled

Label text uses on-background. Override roles at the theme layer, not in component CSS.

Accessibility

  • Every checkbox needs a visible label; use RuiLabel or aria-label.
  • Indeterminate state is exposed with aria-checked="mixed".
  • Disabled checkboxes should include context explaining why the option is unavailable.

API

RuiCheckbox renders a <label> and native <input type="checkbox"> inside the coordinating <rui-checkbox> custom element. Use the JSX view or compose equivalent marked-up light DOM; the browser owns activation and Space-to-toggle.

Attributes (<rui-checkbox>)

AttributeTypeDefaultDescription
checkedbooleanfalseChecked state.
indeterminatebooleanfalsePartially checked (mixed) state; sets indeterminate IDL + aria-checked="mixed".
disabledbooleanfalseDisabled state.
valuestringonValue submitted with forms when checked.
namestring''Form field name on the inner input.

Light-DOM contract

TargetRequiredHost writesAuthor owns
[data-ref="input"]yeschecked, indeterminate, disabled, value, name, aria-checkedthe input element; stamp data-rui-control for field wiring

Do not fight host-owned input state. Nested hosts: none.

Events

EventDetailDescription
inputnoneThe native inner <input> event, bubbling through the host. Read host.checked.
changenoneThe native inner <input> event on commit, bubbling through the host. Read host.checked.

rui-checkbox 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.checked. Act only when event.target is the control's member input. A programmatic write dispatches nothing. A checkbox in a rui-checkbox-group bubbles to the group the same way.

View helpers

ComponentTarget stampedNotes
RuiCheckbox[data-ref="input"] on native checkboxChildren render in rui-checkbox__label. Always stamps data-rui-control.

CSS classes

Public BEM classes (documented via @cssclass):

ClassDescription
.rui-checkboxLabel row: box + visible label.
.rui-checkbox__inputNative input (visually hidden, receives focus).
.rui-checkbox__controlVisible box with check / indeterminate glyph.
.rui-checkbox__labelLight-DOM label text.

Theme roles

PartCSS variables consumed
Box--border, --background
Checked--primary, --on-primary
Indeterminate--primary
Focus ring--focus-ring