Skip to the page
Tactile UI

Kit part · Buttons · Toggles & switches

Toggle key

One key that latches below the plate and stays there. It is the kit’s own key with one state to keep, down or up, so it is the way to say mute, pin, bold or armed without the weight of a switch. A lamp in the cap may light while it is down.

Element
<button class="tui-key tui-toggle-key" data-toggle-key aria-pressed>
Needs
kit.css + kit.mjs
Rules
toggle-key.rules.md · 5
Finishes
Aluminium · Graphite · Oak · Walnut · Porcelain · Black · Daylight · Night · Paper · Phosphor · E-paper · AMOLED
Volumes
Tactile · Quiet
On this page
  1. Variants
  2. Every state, at once
  3. API
  4. Markup
  5. Accessibility
  6. How it’s built
  7. Rules
  8. Related parts

Seats open in 11 days. Want one email that morning?

Variants

Words with a lamp
Words alone
A glyph · --icon
Small · --sm
A lamp of each colour
Disabled, up and down

Every state, at once

Both finishes, side by side. Hover, pressed and focus are forced with .is-hover, .is-down and .is-focus; checked and disabled are real.

Aluminium

PartUpHoverPressingLatchedFocusDisabled
Key
With lamp

Graphite

PartUpHoverPressingLatchedFocusDisabled
Key
With lamp

API

NameKindValuesWhat it does
<button class="tui-key tui-toggle-key">elementwith aria-pressed="true" or "false"The key. Down is aria-pressed="true": the cap sinks below the plate and its lamp lights.
data-toggle-keyattributeon the keyThe script flips aria-pressed on press. Leave it off to set aria-pressed from your own state.
aria-pressedattribute"true" | "false"The state, for the page and for a screen reader. Start every toggle key with one or the other.
aria-labelattributeon a key with no wordsNames a key that shows only a glyph. Keep the name the same whether it is up or down.
.tui-lampclassinside the key, with data-lampThe key’s own lamp: green, amber, red or blue. It is dark while the key is up and lit while it is down.
--sm · --iconmodifieron the keyThe key’s sizes; --icon makes a square cap for a glyph.
tui-toggle-key-changeeventdetail { pressed }Bubbles from the key after it latches or lets go.
toggleKey(key, force?)functiona key, and true or falseLatches, releases or flips a key from code, fires the event and returns the new state.
Space · Enterkeyon the keyLatch it or let it go; it is a button, so both work.

Markup

<!-- Words, with a lamp that lights while the key is down -->
<button class="tui-key tui-toggle-key" type="button" data-toggle-key aria-pressed="false">
  <span class="tui-lamp" data-lamp="amber" aria-hidden="true"></span>Mute
</button>

<!-- A glyph alone: the name is the same up or down, aria-pressed says which -->
<button class="tui-key tui-key--icon tui-toggle-key" type="button" data-toggle-key aria-pressed="true" aria-label="Favourite">
  <svg class="tui-icon" …></svg>
</button>

<!-- Without data-toggle-key you keep aria-pressed yourself, as a framework would -->
<button class="tui-key tui-toggle-key" type="button" aria-pressed="true">Pinned</button>
import { toggleKey } from '/kit/kit.mjs';

const mute = document.querySelector('#mute');
mute.addEventListener('tui-toggle-key-change', (e) => {
  channel.muted = e.detail.pressed;           // true while the key is down
});

toggleKey(mute, true);   // latch it from code
toggleKey(mute);         // flip it

Needs kit.css and kit.mjs. How to install the kit.

Accessibility

  • It is a native <button> with aria-pressed, read as “Mute, toggle button, pressed”, and it works with Space and Enter.
  • The state is the cap sunk below the plate and the lamp lit, and it is also in aria-pressed, so colour is never the only sign of it.
  • The name stays the same up or down. A key that says “Mute” in both states is read right; one that changes to “Unmute” would be read as “Unmute, pressed”.
  • A key that shows only a glyph is named with aria-label, and its glyph is hidden from a screen reader.
  • On a phone the cap is 44px tall. The 70ms press is switched off under reduced motion; the state does not depend on it.

How it’s built

There is almost nothing new under it. The kit’s key already sinks below the plate when it is pressed, and a pressed button is drawn the same way; this part only gives that latched look a meaning, one state kept. The lamp is the kit’s lamp, left unlit in the cap and lit by the key’s own pressed state, so it follows every finish and both volumes with no rule of its own. The script is one listener on the page that flips aria-pressed for any key that asks for it, so keys added later work without being wired.

Rules

toggle-key.rules.mdIn the brain

A single key that stays down: pressed and latched states a screen reader can read, a lamp that lights with it, and no switch where a key will do.

5 rules in this file, with the foundations they rest on and the anti-patterns that break them. Full rules ship in the brain with the Pass.

Key

Every button, and every link that acts like one: a cap on a skirt that drops below the plate when pressed.

Toggle group

The segmented control’s keys, each latching on its own, so any number can be down at once: bold and italic, the columns a table shows, the filters on a log. Every key is a checkbox and posts with the form. A lone toggle is a group of one, and a parting line splits clusters of keys in one slot.

Switch

On or off, applied the moment it moves. A native checkbox with a ridged thumb in a slot that lights green when on.

Segmented control

A row of keys in a tray with one pressed down: pick a view, a range or a mode and it applies at once. It is the kit’s selector without the lamps, with sizes, a full-width row and icon segments.