Skip to main content

Switch

Usage

Definition

The switch is a binary toggle used to turn a function on/off. The switch label can be phrased as a yes/no question, in which case the switch "answers" with yes/no.

Do not use the switch for selection between non-binary alternatives (e.g. this or that). The switch is only used to turn a function on/off.

Common Characteristics

The switch consists of a label, a UI control, and status text indicating the state of the control. Both the control and the text indicator are interactive.

The status text must be be “yes”/”no”, or “on”/”off”.

Function Label

Bidding

Question Label

Do you want to bid?

Switch Label Positions

The switch supports left-, right-, or top-aligned labels.

Label left align

Do you want to bid?

Label right align

Do you want to bid?

Label top align

Do you want to bid?

Code

Default Switch

Live Editor
Result
Loading...

Switch Label Types

Function Label

Live Editor
Result
Loading...

Question Label

Live Editor
Result
Loading...

Switch Label Positions

The switch supports left-, right-, or top-aligned labels.

Label left align

Live Editor
Result
Loading...

Label right align

Live Editor
Result
Loading...

Label top align

Live Editor
Result
Loading...

Prop status false, switch off

Live Editor
Result
Loading...

Prop status true, switch on

Live Editor
Result
Loading...

Disabled and not checked

Live Editor
Result
Loading...

Disabled and checked

<Switch label="Bidding" statusText="OnOff" status={true} disabled={true} />

Prop status false, switch off

Live Editor
Result
Loading...

Prop status true, switch on

Live Editor
Result
Loading...

Switch Props

propertypropTyperequireddefaultdescription
disabledboolnofalseDetermines whether or not the switch appears to be disabled and is unclickable.
labelstringyes-Controls the text that will appear in the text label associated with the switch
labelAlignment'top' | 'left' | 'right'noleftDetermines whether the text label associated with switch appears to the left of the containing element, to the immediate right of the switch itself regardless of containing element, or on top of the switch.
onChangefuncno-Enables the consumer of this component to hook into the onChange event when toggled.
statusboolnofalseIf status is false the switch will be in left most position, if true it will be in right most
statusText'OnOff' | 'YesNo'yesOnOffDetermines the text that will appear to the right of the switch
size'lg' | 'md' | 'sm'no'md'Enables the label size to large 'lg' or small 'sm'
readonlyboolnofalseEnables the readonly State