Primitives
Perform state toggling.
Import the Switch primitives from ng-primitives/switch
.
import { NgpSwitch, NgpSwitchThumb } from 'ng-primitives/switch';
Assemble the switch directives in your template.
<button ngpSwitch [(ngpSwitchChecked)]="checked">
<span ngpSwitchThumb></span>
</button>
Here are some additional examples of how to use the Switch primitives.
The switch automatically integrates with the form field primitives.
The following directives are available to import from the ng-primitives/switch
package:
Apply the ngpSwitch
directive to an element to manage the checked state.
[ngpSwitch]
ngpSwitch
The following data attributes are applied to the ngpSwitch
directive:
Attribute | Description | Value |
---|---|---|
data-checked |
The state of the switch. | true | false |
data-disabled |
The disabled state. | true | false |
data-hover |
The hover state. | true | false |
data-focus-visible |
The focus state. | true | false |
data-press |
The pressed state. | true | false |
Apply the ngpSwitchThumb
directive to an element within a switch to represent the thumb.
[ngpSwitchThumb]
ngpSwitchThumb
The following data attributes are available to style the thumb:
Attribute | Description | Value |
---|---|---|
data-checked |
The state of the switch. | true | false |
data-disabled |
The disabled state. | true | false |
data-hover |
The hover state. | true | false |
data-focus-visible |
The focus state. | true | false |
data-press |
The pressed state. | true | false |
Adheres to the WAI-ARIA switch design pattern.
Copyright © 2024 Angular Primitives