Switch
Last updated
Last updated
The Switch
allows the user to make a basic "Yes or No" decision, i.e. it represents an input for a boolean value. This is useful either as part of a form, or as a stand-alone toggle for basic filters for tables and similar use cases.
The Switch
component offers the following configuration properties.
Property | Type | Default value | Behavior |
---|---|---|---|
Default value |
|
| Determines whether the initial state of the switch should be active or not. If used with dynamic JavaScript expressions, this can reactively update the toggle based on specific conditions. |
Disabled |
|
| Whether the switch should be disabled or not. When disabled, the input is greyed out and cannot be toggled. |
Label |
|
| Label that is rendered next to the toggle element. |
Label alignment |
|
| Text alignment of the label. |
Label position |
|
| Determines whether the toggle should be placed to the left of the label or to the right. |
Required |
|
| Determines how the switch behaves as part of a form during submit. When set to |
Toggle with label click |
|
| Determines whether the switch can be toggled only by clicking the toggle directly ( |
The Switch
offers three events, that are all related to the UI event when the switch is toggled:
On change: This event is triggered whenever the switch is toggled, regardless whether activated or deactivated.
On false: This event is triggered whenever the switch is deactivated. This is equivalent to an action running at "On change", with a condition like if (!mySwitch.value) { ... }
inside.
On true: This event is triggered whenever the switch is activated. This is equivalent to an action running at "On change", with a condition like if (mySwitch.value) { ... }
inside.
The Switch
exposes the following API in the JavaScript runtime environment.
Property / Function | Type | Behavior |
---|---|---|
|
| Resets the switch to inactive ( |
|
| Current boolean value of the "Disabled" property. |
|
| Current string value of the "Label" property. |
|
| Resets the switch similar to the |
|
| Sets the value of the "Disabled" property to the provided boolean value. |
|
| Sets the value of the "Label" property to the provided string value. |
|
| Sets the toggle-state to the provided boolean value. This does not trigger any events. |
|
| Current boolean value representing the toggle-state of the switch. Will return |