Switch Group

A group of switches. In the following example, the group is exclusive (the default), and items can be unselected, unlike with a traditional radio group:

Spice level

Choice: mild

Enjoy a subtle hint of spice that adds a gentle kick to your chocolate without overwhelming the palate


Headless component

Similarly to the toggle group, the headless component is built in a few lines of code by applying the Group mixin to the Switch class. So all the heavy-lifting is done by the Group mixin, like tracking the active items and managing focus

import { Group } from "chocobytes/blocks/group.svelte.js";
import { Switch, type SwitchOptions } from "chocobytes/headless/switch.svelte.js";

export class SwitchGroup extends Group(Switch) {
  createItem = (options?: SwitchOptions) => {
    return new this.Item(options);
  };
}

You have access to all the Group focus options like loop, exclusive etc. In the following demo the group behaves almost like a radio group except this one doesn’t loop. You can use the keyboard arrows to play with it:

selected heat:
mild