A switch allows users to toggle the state of a single setting.
Switches provide a way to toggle between two states with a visual indicator of the current state. A label can be positioned on the left, right, top, or bottom of the switch.
<daff-switch>Reminder</daff-switch>
Import DAFF_SWITCH_COMPONENTS into your component:
import { DAFF_SWITCH_COMPONENTS } from '@daffodil/design/switch';
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
imports: [
DAFF_SWITCH_COMPONENTS,
],
})
export class CustomComponent {}
A switch consists of a toggle control with a label projected as content:
<daff-switch>Wi-Fi</daff-switch>
<daff-switch>: The switch control. The label is provided as projected content and is automatically associated with the toggle.A small switch variant is available for dense layouts. Use the size="sm" property to render a more compact version of a switch.
<daff-switch>Default</daff-switch> <daff-switch size="sm">Small</daff-switch>
Use the disabled property on switch to make it non-interactive.
<daff-switch [disabled]="true">Disabled</daff-switch>
Use the labelPosition property to control the visual relationship between the switch and its label. By default, labels appear to the left of the switch control.
<daff-form-field>
<daff-form-label>Label position</daff-form-label>
<daff-select [options]="options" [formControl]="labelPositionControl">
<ng-template daffSelectOption let-option="option">
{{ option.label }}
</ng-template>
</daff-select>
</daff-form-field>
<daff-switch
[labelPosition]="labelPositionControl.value?.value"
[formControl]="labelSwitchExample"
ngDefaultControl>
Label
</daff-switch>
Switch follows the ARIA Switch design pattern.
<button> element with a role of switch.aria-checked is used to indicate the switch's on/off state.id using aria-labelledby.| Key | Action |
|---|---|
| Tab | Moves focus to or away from the switch control. |
| Space | Changes the switch's state between on and off. |
| Enter | Changes the switch's state between on and off. |