6.2 KiB
templateEngineOverride, layout, title, description, toc
| templateEngineOverride | layout | title | description | toc | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| njk | layouts/page.njk | Switch | A control that allows the user to toggle between checked and not checked. |
|
{% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %}
{% set code %}
Usage
Add role="switch" and the input class to a native <input type="checkbox">. Use a native <label> or aria-label for accessible naming.
{% set code %}{% endset %} {{ code_block(code) }}
Checked state
Use native HTML state. Add checked for an initially enabled switch, or read and update the element's checked property in JavaScript.
{% set code %}{% endset %} {{ code_block(code) }}
Invalid state
Set aria-invalid="true" on the switch and, when using field, set data-invalid="true" on the field wrapper.
{% set code %}
Choose whether marketing emails are enabled.
Examples
Basic
{% set code %}
Description
{% set code %}
Receive emails about new products, features, and more.
Choice Card
Wrap a .field in a native <label> when the whole card should toggle the switch.
{% set code %}
Disabled
{% set code %}
Invalid
{% set code %}
Choose whether marketing emails are enabled.
Size
{% set code %}
RTL
Switch field layout uses document direction. Set dir="rtl" on a parent to render right-to-left.
{% set code %}