Dark Light
System
Default LBBW Jira Confluence Source Code
Share
Playground

Switch

<afp-switch> Since 1.0.0 stable This component uses the light DOM, so its markup and styles are part of the regular document flow.

A switch component to toggle between on and off states.

Switch

Examples #

Shapes #

Use the shape attribute to change a switch's shape.

Pill Rounded Soft Square

Sizes #

Use the size attribute to change a switch's size.

Small Medium Large

Hint #

Use the hint attribute to add a hint to the switch.

Switch with hint

Checked #

Use the checked attribute to set the switch to be checked by default.

Checked

Disabled #

Use the disabled attribute to disable the switch.

Unchecked Checked

Value #

Use the afp-value-changed event to listen for value changes.

Click me

Customization #

Use the --afp-switch-color CSS variable to customize the switch color.

Custom 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
Name Description
SMALL
Small size with compact dimensions.
MEDIUM
Medium size with standard dimensions.
LARGE
Large size with expanded dimensions.
AfpSize
Default AfpSize.MEDIUM
shape
shape of the switch
Type
AfpShape
Name Description
PILL
Makes the component circular.
ROUNDED
Makes the component rounded.
SOFT
Makes the component have soft edges.
SQUARE
Makes the component square.
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';
Share
Create a link with a predefined theme that is automatically applied when the generated link is opened. Default LBBW Presentation Mode
Abort Copy Link