# Toggle Group

> Source: https://design.nanatec.co.ke/components/toggle-group/
> A row of buttons that press and release, any number at once or one at a time, such as text styles or the filters on a list.

The toggle group is a row of buttons that stay pressed until they are pressed again: the
Bold, Italic and Underline of an editor, or the kinds of cover a list is filtered by. Any
number can be pressed at once, or, with `type="single"`, one at a time. For one choice
that is always made and submitted with a form, such as a payment plan, use a
[radio group](/components/radio-group/) of [radio buttons](/components/radio-button/);
for a single on/off button, a [toggle button](/components/button/#toggle).

## Preview

## Installation

```html
<nana-toggle-group label="Text style" value="bold">
  <nana-toggle-group-item value="bold">Bold</nana-toggle-group-item>
  <nana-toggle-group-item value="italic">Italic</nana-toggle-group-item>
  <nana-toggle-group-item value="underline">Underline</nana-toggle-group-item>
</nana-toggle-group>

<script type="module">
  document.querySelector('nana-toggle-group').addEventListener('nana-change', (event) => {
    console.log(event.detail.value);
  });
</script>
```

`value` is a list, in the items' order, even in a single group, where it holds one value
or none. As an attribute it is space-separated: `value="bold italic"`. `nana-change`
reports each new list.

## One at a time

With `type="single"`, pressing an item releases the one before it, and pressing the
pressed item releases it, leaving none. Add `required` to keep one pressed always, as in
the Period group above. `required` in a multiple group keeps the last item from being
released.

In a single group the pressed fill flows from the old item to the new one, as the tabs'
thumb does; with reduced motion it moves at once. Every item presses in slightly when it
is clicked or tapped.

## Icons

An item can show only an icon. Give it an `aria-label`, since the icon names nothing:
