Switch
3 Switch variations from the W3C ARIA Authoring Practices Guide.
Switch
An on/off switch built from a custom span. Its name remains stable.
Example
Keyboard interaction
Space toggles the switch. Custom and button versions also accept Enter.
Events
Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.
axxy-switch-change— Dispatched when the switch toggles on or off. (target:[role="switch"], detail:{ checked: boolean })input / change— Standard input and change events. (target:[role="switch"], detail:Native Event)
Example HTML
<axxy-scope>
<span role="switch" aria-checked="false">Switch</span>
</axxy-scope>Switch (Checkbox)
An on/off switch built from a native checkbox input. Its name remains stable.
Example
Keyboard interaction
Space toggles the switch. Custom and button versions also accept Enter.
Events
Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.
axxy-switch-change— Dispatched when the switch toggles on or off. (target:[role="switch"], detail:{ checked: boolean })input / change— Standard input and change events. (target:[role="switch"], detail:Native Event)
Example HTML
<axxy-scope>
<label>
<input type="checkbox" role="switch">
Switch
</label>
</axxy-scope>