Switch
<afp-switch>
A switch component to toggle between on and off states.
Examples #
Shapes #
Use the shape attribute to change a switch's shape.
Sizes #
Use the size attribute to change a switch's size.
Hint #
Use the hint attribute to add a hint to the switch.
Checked #
Use the checked attribute to set the switch to be checked by default.
Disabled #
Use the disabled attribute to disable the switch.
Value #
Use the afp-value-changed event to listen for value changes.
Customization #
Use the --afp-switch-color CSS variable to customize the switch color.
Properties
Learn more about properties.
| Name | Description | Reflects | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
checked
|
value of the switch
Type
boolean
Default
false |
|
||||||||||
value
|
value of the switch
Type
string
|
|||||||||||
hint
|
hint text for the switch
Type
string
|
|
||||||||||
ariaLabel
arialabel
|
Aria label for the switch.
This is used for accessibility purposes to provide a text alternative for screen readers.
Type
string
|
|
||||||||||
size
|
size of the switch.
Type
AfpSize
Default
AfpSize.MEDIUM |
|
||||||||||
shape
|
shape of the switch
Type
AfpShape
Default
AfpShape.PILL |
|
||||||||||
disabled
|
disabled property of the switch
Type
boolean
Default
false |
|
Events
Learn more about events.
| Name | Return | Description |
|---|---|---|
afp-focus
|
void
|
Emitted when the switch gains focus.
|
afp-blur
|
void
|
Emitted when the switch loses focus.
|
afp-value-changed
|
{value: string; checked: boolean}
|
Emitted when the switch value changes.
|
Slots
Learn more about slots.
| Name | Description |
|---|---|
default
|
The default slot used for the switch label.
|
CSS Parts
Learn more about CSS Parts.
| Name | Description | Selector |
|---|---|---|
wrapper
|
The wrapper element around the switch component.
|
::part(wrapper)
|
base
|
The base element of the switch.
|
::part(base)
|
slider
|
The slider element of the switch.
|
::part(slider)
|
label
|
The label container of the switch.
|
::part(label)
|
hint
|
The hint text element of the switch.
|
::part(hint)
|
CSS Custom Properties
| Name | Description | Default |
|---|---|---|
--afp-switch-disabled-opacity
|
The opacity of the switch when disabled.
|
0.5
|
--afp-switch-color
|
The main color of the switch.
|
--afp-color-brand-50
|
Importing
Using the bundle is the recommended method to include components. If you’d rather handle imports manually, you can use the code examples below.
import '@afp-design-system/core/dist/components/switch/switch.js';