Toggle Group

A group of toggle buttons. The group binding gives you the familiar Svelte feel.

Select your chocolate toppings

Choice: salt,crunch


Headless component

The headless component is built in a few lines of code by applying the Group mixin to the ToggleButton. 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 type { Required } from "chocobytes/utils/types.js";
import { ToggleButton, type ToggleOptions } from "chocobytes/headless/toggle.svelte.js";

export class ToggleGroup extends Group(ToggleButton) {
  createItem = (options: Required<ToggleOptions, "value">) => {
    return new this.Item(options);
  };
}

You have access to all the Group focus options like loop, exclusive etc. and the group property is bindable as demonstrated in the following demo. Use the keyboard arrows to play with the loop:

Choice: nuts