Skip to main content

Switch

The Switch component allows users to toggle between two different states. You can set a specific initial value using the defaultValue prop for an uncontrolled switch or setting the initial value of the state of a controlled switch accordingly. The name prop also needs to be specified for identifying the Switch when submitting it in a form.

SwitchProps

Signature:

export declare type SwitchProps = <, (checked: , event?: <>) => | > & & & & & { /** The used as the value of the switch when submitting it in a form, if the switch is toggled on. */ formValue?: ; };

SwitchBaseProps

extends, , , , ,
NameTypeDefaultDescription
formValue?
-The string used as the value of the switch when submitting it in a form, if the switch is toggled on.
disabled?
falseWhether the switch is disabled or not. If true, the switch cannot be clicked in order to toggle its state.
required?
falseWhether the switch is required or not. If true, the switch is marked with an asterisk.

SwitchControlledProps

NameTypeDefaultDescription
value
-Whether the switch is on or off.
onChange
(checked: , event?: <>) =>
-Handler that is called when the 'on' attribute changes.
name?
-The name used for the switch, that identifies it when submitting it in a form.

SwitchUncontrolledProps

NameTypeDefaultDescription
defaultValue?
falseThe default on or off state.
name
-The name used for the switch button, that identifies it when submitting it in a form.
Still have questions?
Find answers in the Dynatrace Community