2.14.0
Switches afford a choice between one of two opposing states or options.
<div class="mds-switch">
<label class="mds-switch__label" for="--80123">
<input id="--80123" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<mds-switch id="switch-1"> Logic Mode </mds-switch>
<div class="mds-switch mds-switch--disabled">
<label class="mds-switch__label" for="--40941">
<input id="--40941" type="checkbox" role="switch" class="mds-switch__input" disabled>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<mds-switch disabled id="switch-6"> Logic Mode </mds-switch>
Use when the purpose of a switch is clearly implied by its proximity to other content and controls.
<div class="mds-switch mds-switch--hide-label">
<label class="mds-switch__label" for="--22181">
<input id="--22181" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<mds-switch hide-text id="switch-8"> Logic Mode </mds-switch>
<div class="mds-switch mds-switch--disabled">
<label class="mds-switch__label" for="--83664">
<input id="--83664" type="checkbox" role="switch" class="mds-switch__input" disabled>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<mds-switch hide-text disabled id="switch-13"> Logic Mode </mds-switch>
<fieldset class="mds-switch__group" role="group">
<legend class="mds-switch__group-label"> Client Configuration Options </legend>
<div class="mds-switch">
<label class="mds-switch__label" for="--72833">
<input id="--72833" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Display Overview/Investment </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--75775">
<input id="--75775" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Display Account Details </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--63449">
<input id="--63449" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Display Benchmark Returns </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--42476">
<input id="--42476" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Allow Clients to Generate Reports </span>
</label>
</div>
<div class="mds-switch">
<label class="mds-switch__label" for="--51875">
<input id="--51875" type="checkbox" role="switch" class="mds-switch__input">
<span class="mds-switch__text"> Display Document Manager </span>
</label>
</div>
</fieldset>
<fieldset class="mds-switch__group" role="group">
<legend class="mds-switch__group-label"> Client Configuration Options </legend>
<mds-switch id="switch-15"> Display Overview/Investment </mds-switch>
<mds-switch id="switch-16"> Display Account Details </mds-switch>
<mds-switch id="switch-17"> Display Benchmark Returns </mds-switch>
<mds-switch id="switch-18"> Allow Clients to Generate Reports </mds-switch>
<mds-switch id="switch-19"> Display Document Manager </mds-switch>
</fieldset>
Sizing affects the switch size, text size, and internal spacing. The default size is medium, and you can use modifier classes or props to make the switch smaller or larger.
<div class="mds-switch mds-switch--small">
<label class="mds-switch__label" for="--25215">
<input id="--25215" type="checkbox" role="switch" class="mds-switch__input" checked>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<br />
<div class="mds-switch mds-switch--small mds-switch--hide-label">
<label class="mds-switch__label" for="--60090">
<input id="--60090" type="checkbox" role="switch" class="mds-switch__input" checked>
<span class="mds-switch__text"> Logic Mode </span>
</label>
</div>
<mds-switch size="small" id="switch-20" checked> Logic Mode </mds-switch>
<br />
<mds-switch size="small" id="switch-21" hide-text checked> Logic Mode </mds-switch>
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
At parent level, this applies base-switch styles to an element. |
|
|
Adjusts styling to render a small switch. |
|
|
Adjusts styling to render a large switch. |
|
|
Applies hover state. |
|
|
Applies active state. |
|
|
Applies focus state. |
|
|
Applies disabled state. To properly disable interaction with the switch, add |
|
|
Hides label text although text is still readable by screen readers. |
|
|
Semantically structures a group of switches. Always include |
|
|
Apply to a parent wrapper of a fieldset to convert switches layout from vertical to horizontal. |
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
Boolean |
— |
|
Sets the |
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
Boolean |
— |
|
If |
|
Boolean |
— |
|
If |
|
String |
Required |
— |
The |
|
String |
Enum: |
|
Alters the size of the switch. |
|
String |
Required |
— |
Sets the switch’s label text. Can also be passed using the default slot. |
hideText
would be written as hide-text
.Any text passed in between the <mds-switch></mds-switch>
tags will be used as the text content.
Setting text
, checked
, and size
:
<!-- Using Props -->
<mds-switch text="Switch Label" size="large" checked></mds-switch>
<!-- Using Slots -->
<mds-switch size="large" checked> Switch Label </mds-switch>
role="switch"
ARIA attribute to ensure they are accurately announced via assistive technologies.role="group"
on the <fieldset>
wrapping grouped switches.spacebar
.