Switch Group
Lays out switches as one group, with an optional list style and option descriptions.
Usage
import { Switch } from '@epilot/spark-ui/switch'
import { SwitchGroup } from '@epilot/spark-ui/switch-group'function Charging() {
return (
<SwitchGroup aria-label="Charging">
<label className="flex items-center gap-3">
<Switch defaultChecked />
<span>Solar charging</span>
</label>
<label className="flex items-center gap-3">
<Switch />
<span>Cheap-rate charging</span>
</label>
</SwitchGroup>
)
}SwitchGroup is layout only: it renders role="group" and spaces its children, but
holds no value. Each Switch keeps its own boolean, so control each one with its own
checked and onCheckedChange. This differs from
Checkbox Group, which owns a string[]. Props and
slots otherwise mirror Radio's RadioGroup.
Use SwitchGroup for settings that apply as soon as they flip. Use
CheckboxGroup when the choices are saved together with a form submit. Use RadioGroup
when exactly one option is allowed. See Selection groups.
Examples
List styles
Set listStyle to show the switches as a list of SelectionItem rows with a
description under each label. SelectionItem takes the Switch as control.
API Reference
SwitchGroup
All native <div> props, plus:
| Prop | Type | Default | Description |
|---|---|---|---|
listStyle | "soft" | "surface" | "outlined" | "ghost" | none | Shows the options as a styled list of SelectionItem rows. Without it the group is a plain stack. Ignores gap. |
styleVariant | "solid" | "soft" | "surface" | "outline" | solid | Style of each switch control. Independent of listStyle. |
color | "accent" | "neutral" | "danger" | accent | Re-colors each switch control. |
gap | number | 3 | --spark-layout-gap units between switches. Ignored when listStyle is set. |
className | string | — | Merges with the base styles. |
SelectionItem is documented on Checkbox Group.
Accessibility
SwitchGrouprendersrole="group". Inside aFieldSet, the<fieldset>and<legend>name the set; outside one, passaria-labeloraria-labelledbyto the group.- The group has no required or error state of its own, because switches are independent booleans. A
FieldSetaround it still carries a hint throughFieldDescription, and aFieldErrorin thatFieldSetstill tints the list and legend. SelectionItemnames each switch by itslabeland describes it by itsdescription.- Keyboard:
Tabmoves between switches,Spacetoggles the focused one. - A switch that applies immediately needs visible feedback that it applied; do not leave the change silent.