Skip to content
Slotted

Checkbox Group

Several choices out of one set, held as one array of values in the order the set declares them.

Notify me about failed payments by

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { Checkbox, CheckboxGroup, CheckboxGroupDefaultsProvider } from '@slotted/react';

Orientation

A set flows vertically by default. orientation="horizontal" lays the boxes in a row for short labels, such as statuses in a filter bar, and the row wraps instead of scrolling when it runs out of width. Every box stays its own tab stop in both orientations.

Invoice status

Sizes

size sets the boxes, the labels and the spacing: sm for dense panels and toolbars, md for most forms, lg for sparse forms. Inside a field or a field group the checkbox group takes their size, so one prop sizes the legend and the boxes together.

Show columns
Ship from
Accept payment by

Label placement

labelPlacement="start" puts each label first and the boxes in a column at the end of the row, as in a settings panel where the labels are read first. The placement is set once for the set, so the boxes line up with each other.

Email reports

Tiles

variant="tile" frames every choice and makes its whole surface the target, for a choice that needs a price or a sentence beside its name, such as add-ons on a plan. The variant is set once for the set. The checkbox group does not arrange the tiles: put a Grid around them for equal widths and equal heights.

Add-ons

$29 per month. Every change kept for a year.

$49 per month. SAML and SCIM provisioning.

$99 per month. Replies within four hours.

Descriptions

A description under one box says what that choice does. In React it is the description prop of Checkbox; in Angular it is a slCheckboxDescription element inside the box. It joins that box’s accessible description only, and pressing it does not toggle the box.

When stock runs low

Sent to the buyer for the SKU when on-hand drops below the reorder point.

Created for the preferred supplier at the usual order quantity, waiting for approval.

The product page shows Out of stock instead of a delivery date.

Select all

A Checkbox with parent checks and unchecks the whole set. It needs allValues, the list of every value the checkbox group holds. The parent box is checked when every value is selected, mixed when some are, and unchecked when none are; you write no state for it. Pressing it replaces the whole selection. allValues also keeps the selection in the order of that list rather than in the order the boxes were pressed.

Columns to export

Selection count

Inside a field, showCount draws how many values are selected out of allValues at the end of the label row, as 2/4, and adds that count to the group’s accessible description. The field’s label names the group. The count updates as boxes are pressed.

2/4

Orders ship from the nearest selected warehouse.

Unavailable option

disabled on one Checkbox takes that choice alone out of the tab order and out of form submission, while the rest of the set stays usable. Its description can say what turns it on.

Send order updates by

Add a mobile number to the customer record to turn this on.

States

invalid sets aria-invalid on the group and on every box and draws every box in the danger tone; the field group’s error says what is wrong. Set readOnly and disabled on the field group, which passes them to the checkbox group: read-only keeps every box focusable and refuses every change, and disabled takes the whole set out of the tab order and out of form submission.

Sales regions

Error:Choose at least one region for this price list.

Tax exemptions

Set by the finance team on the customer record.

Carriers

Carriers open once a ship-from address is saved.

Controlled

Pass value and update it from onValueChange in React or (valueChange) in Angular when other parts of the screen depend on the selection. The request carries the new array, its reason (pointer or keyboard) and cancel(), which refuses the change before any box moves. Without value, the checkbox group keeps the selection itself and starts from defaultValue.

Payment method
Showing 957 orders

Validation on submit

A checkbox group inside a required field group carries aria-required, and never the native required, which on a checkbox would demand that one particular box be checked. Validate when the form is submitted, then set invalid and write the field group’s error; live="polite" announces the error once, and reserve keeps its line open so the boxes do not move. In Angular the checkbox group is also a form control: bind formControl, formControlName or ngModel on it, and inside a required field group its validator fails with required while the selection is empty. Submit with nothing checked, then check a channel and submit again.

Send shipping confirmations by

Error:

Defaults for a section

A defaults provider sets orientation, labelPlacement, variant and size once for every checkbox group under it. A checkbox group that states a value of its own keeps it, and a field or field group around it decides size before the provider does.

Fulfilment
Sales channel

Accessibility

  • The WAI-ARIA Authoring Practices have no pattern for a group of checkboxes: the Checkbox pattern covers one box, and grouping is a question of naming rather than of keyboard behavior. The sources are the ARIA group role and the Providing Accessible Names and Descriptions practice (w3.org/WAI/ARIA/apg/practices/names-and-descriptions/).
  • Every box is its own tab stop, and Space toggles the box that has focus. The platform provides this whole keyboard model. It is what sets a checkbox group apart from a radio group, where the set is a single tab stop and the arrow keys move the choice.
  • The role depends on the container. A field group is a fieldset with a legend, which is already a named group to assistive technology; a role="group" inside it, named by the same legend, would announce the set twice. Inside a field group the checkbox group renders no role, and the legend names the set. Inside a field, the field’s label names the group through aria-labelledby.
  • The group writes aria-required, never the native required on a box. The native attribute on a checkbox demands that one particular box be checked, which is not what "choose at least one" means, and it turns on browser constraint validation.
  • A checkbox has no native read-only state, so the checkbox group enforces one: every box refuses the change on the click that a pointer and Space share, aria-readonly announces it, and every tab stop and focus ring stays.
  • The parent box is derived from the set rather than kept as a state of its own, so it always agrees with the boxes it controls. It reports aria-checked="mixed" through the platform’s indeterminate property, and pressing it replaces the selection instead of adding a value of its own.

API

CheckboxGroup

Props

valuereadonly string[]
The controlled selection. When present, the consumer owns the selection for the life of the component. When absent, the checkbox group owns it and starts from defaultValue.
defaultValuereadonly string[]Default []
The selection an uncontrolled group starts from, read once.
allValuesreadonly string[]
Every value the checkbox group holds. A parent Checkbox needs it: the parent is checked when every value is selected and mixed when some are, which a selection alone cannot tell. It also keeps the selection in the order of this list rather than in the order the boxes were pressed.
variant'plain' | 'tile'Default plain
On CheckboxGroup, CheckboxGroupDefaultsProviderHow every choice is drawn, passed to every box. tile frames each choice and makes its whole surface the target. Arranging the tiles is left to Grid.
orientation'vertical' | 'horizontal'Default vertical
On CheckboxGroup, CheckboxGroupDefaultsProviderHow the choices flow. A horizontal set wraps instead of scrolling.
size'sm' | 'md' | 'lg'Default md
On CheckboxGroup, CheckboxGroupDefaultsProviderThe type step, passed to every box. A field or field group around the checkbox group decides it first, then the provider.
labelPlacement'end' | 'start'Default end
On CheckboxGroup, CheckboxGroupDefaultsProviderWhich side of its label each box is on, set once for the set so the boxes line up.
namestring
The submission name every box shares when it sets none of its own. No name is generated: the platform does not group checkboxes by name the way it groups radios.
disabledbooleanDefault from the field, or false
Unset rather than false. Reaches every box as the native attribute, which takes the boxes out of the tab order and out of form submission.
readOnlybooleanDefault from the field, or false
Unset rather than false. Every box keeps its tab stop, its focus ring and its contrast, writes aria-readonly, and refuses every change.
invalidbooleanDefault from the field, or false
Unset rather than false. Writes aria-invalid on the group and on every box, and data-invalid on the group’s root and on every box’s root.
requiredbooleanDefault from the field, or false
Unset rather than false. Writes aria-required on the group, never the native required, which on a checkbox would demand that one particular box be checked.
showCountbooleanDefault false
Inside a field, draws how many of allValues are selected at the end of the field’s label row, as 2/4, and adds that count to the group’s accessible description.

Events

NamePayloadWhen
onValueChange(value: readonly string[], request: ChangeRequest<readonly string[]>)Before the selection moves. request.value is the new array and request.previous the array it replaces. request.reason is pointer or keyboard, recovered from the box’s click; request.source is the originating event; request.cancel() refuses the move before anything commits, including the platform’s own toggle.
onCheckedChange, on each Checkbox(checked: boolean, request: ChangeRequest<boolean>)Before that one box moves, and before the checkbox group builds its own request. Cancelling it also stops the group’s request, so one option can refuse to be chosen without the rest of the set taking part.

Composition

render(props: CheckboxGroupRootProps) => ReactNode
Replaces the root and hands it every attribute. The props are typed as HTMLAttributes<HTMLElement>, so a set of choices can render as a ul with each box as an li.
useCheckboxGroup()() => CheckboxGroupContextValue | undefined
On inside a CheckboxGroupReturns what a box reads: whether it is selected, its size, and how to request a change. It returns undefined outside a checkbox group, so one Checkbox serves both a single consent box and a member of a set.
CheckboxGroupDefaultsProvider{ size, variant, orientation, labelPlacement }
On a subtreeThe four decisions an application takes once for every checkbox group under it. A field or field group around a checkbox group decides size before the provider.
className / stylestring / CSSProperties
Reach the root. Every other native prop reaches it too, because the root is the only element the checkbox group renders.
rolestringDefault group, or none inside a field group
A role the consumer writes wins. Otherwise the role is group, withdrawn inside a field group, because a fieldset with a legend is already a named group and a second group named by the same legend announces the set twice.
aria-label / aria-labelledbystringDefault the field’s label, inside a field
Names the group. Inside a field, aria-labelledby points at the field’s label unless the consumer writes either attribute. Outside a field and a field group, write one of them, because a group needs a name.

Parts

PartElementRequiredPurpose
rootdiv, or the element render returnsYesThe only part. It arranges the boxes, holds the selection, and carries data-ui="checkbox-group", data-size, data-variant and data-orientation, and data-disabled, data-invalid and data-readonly. Its role is group; inside a field group the role is withdrawn, because the fieldset and its legend already name the set. Inside a field, aria-labelledby points at the field’s label. The boxes inside are Checkbox components with their own stylesheet, which the checkbox group’s stylesheet never selects into.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every checkbox group inside it.

Checkbox Group tokens

TokenDefault
--slotted-checkbox-group-gapvar(--_gap)

Theme tokens it reads

TokenDefault
--slotted-control-gap-lgcomfortable 8px · compact 6px · dense 6px
--slotted-control-gap-mdcomfortable 8px · compact 6px · dense 4px
--slotted-control-gap-smcomfortable 6px · compact 4px · dense 4px