Components
Switch
An on/off setting drawn as the iOS switch: role=switch on a checkbox, Accent when on.
Live example
Rendered with the real classes from /site/chitransit.css, light (left) and dark (right).
.ct-switchcheckeddisabledCode
<label class="sd-switch-row">Show line letters <input type="checkbox" role="switch" class="ct-switch"></label>
<label class="sd-switch-row">Train vehicles <input type="checkbox" role="switch" class="ct-switch" checked></label>
<label class="sd-switch-row">Live Activities <input type="checkbox" role="switch" class="ct-switch" checked disabled></label>
Tokens
From tokens/components.tokens.json. Override one instance by setting the property without the ct- prefix.
| Custom property | Value | Alias | Resolves to |
|---|---|---|---|
--ct-switch-background-checked | var(--accent) | {colors.accent} | #0B4EA2 #92B8F5 |
--ct-switch-background | var(--switch-track) | {colors.switchTrack} | #838995 #6A7488 |
--ct-switch-duration | var(--motion-control-duration) | {motion.controlDuration} | .15 s |
--ct-switch-height | var(--size-switch-height) | {size.switchHeight} | 31 pt |
--ct-switch-radius | var(--radius-pill) | {radius.pill} | 999 pt |
--ct-switch-target | var(--size-minimum-tap-target) | {size.minimumTapTarget} | 44 pt |
--ct-switch-thumb | var(--size-switch-thumb) | {size.switchThumb} | 27 pt |
--ct-switch-thumb-shadow | var(--shadow-control) | {shadows.control} | |
--ct-switch-width | var(--size-switch-width) | {size.switchWidth} | 51 pt |
Contract
Contract: components/switch.yaml. States are drawn live by transit.js.
Loading the contract…
Variants
One form; no variants. .ct-switch goes on <input type="checkbox" role="switch">; checked and disabled are its only states. Nothing else exists.
<!-- Do -->
<label>Train vehicles <input type="checkbox" role="switch" class="ct-switch" checked></label>
<!-- Don't: a switch between two named options; use a segmented control -->
<label>Minutes or arrival time <input type="checkbox" role="switch" class="ct-switch"></label>
Usage
Do
- Put the switch at the trailing end of a settings row whose
<label>names it, so the row toggles it. - Apply the change at once; a switch never needs a Save button.
Don't
- Don't use a switch for a choice between two named options; use a segmented control.
Accessibility
- A checkbox input with
role="switch"is announced as a switch, on or off. - On and off differ by thumb position as well as color.
- The hit area is at least 44pt through an invisible
::before.