Toggle Group¶
A wrapping row of pills for choosing any number of options. The page owns the state. The kit styles aria-pressed, and nothing flips it.
Decision¶
| When | Use |
|---|---|
| A short set of independent options, such as notification channels | Toggle Group |
| A set where exactly one is chosen | Pill Group |
| A long set | Check Grid |
Usage¶
<div class="stolon-toggle-group">
<button type="button" class="stolon-toggle" aria-pressed="true"><span class="material-icons">forum</span>Discord</button>
<button type="button" class="stolon-toggle" aria-pressed="false">Email</button>
</div>
view.querySelectorAll('.stolon-toggle').forEach(function (pill) {
pill.addEventListener('click', function () {
pill.setAttribute('aria-pressed', pill.getAttribute('aria-pressed') === 'true' ? 'false' : 'true');
});
});
Classes: stolon-toggle-group, stolon-toggle.
States and Modifiers¶
- A pressed pill has full opacity, an accent border, and an accent tint.
- The pills are native buttons, so Space and Enter work and
aria-pressedis announced. They wrap at 375px. - A toggle takes the same hover, focus ring, and disabled look as a Pill Group pill, and the group shares its row.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
| Class | What it looks like |
|---|---|
stolon-toggle |
A wrapping row of on and off pills, for choosing any number, in the stolon-toggle-group row the pill group shares. One pill: dim when off, accent tinted when its aria-pressed is true |
Example¶
Example Code¶
<!-- title: Toggle Group -->
<div class="stolon-toggle-group">
<button type="button" class="stolon-toggle" aria-pressed="true"><span class="material-icons">forum</span>Discord</button>
<button type="button" class="stolon-toggle" aria-pressed="false"><span class="material-icons">mail</span>Email</button>
<button type="button" class="stolon-toggle" aria-pressed="true">Webhook</button>
</div>
<script type="module">
await window.__baseReady;
document.querySelectorAll('.stolon-toggle').forEach((pill) => {
pill.addEventListener('click', () => {
pill.setAttribute('aria-pressed', pill.getAttribute('aria-pressed') === 'true' ? 'false' : 'true');
});
});
</script>