Skip to content

Switch

<tpg-switch></tpg-switch>

Switch is a Selection control component that allows the user needs to toggle a single item on or off

The difference between Switch and Checkbox is that Switch will trigger a state change directly when you toggle it, while Checkbox is generally used for state marking, which should work in conjunction with submit operation.

Furthermore, Switches are also different from Check Buttons, the latter are also used in state marking but usually in forms and task-oriented workflows

Component behavior

The switch will respond to click inside the entirety of its area while not disabled, or from “Enter” and “Space” keys while having k-focus.

Examples

Switch states

label

Use the label attribute to give the switch a label

label-position

Use the label-position attribute to decide the label’s position (trailing or leading). Default is leading

selected

Use the selected attribute to set the switch’s selected state

disabled

Use the disabled attribute to disable the switch

read-only

Use the read-only attribute to make the switch read only.

Tables

Properties

Attribute Property Description Type Default Value
label label The textual label of the switch string ''
disabled disabled Disables the switch, just like vanilla HTML boolean false
read-only readOnly Makes the switch read-only boolean false
selected selected Sets the state of the switch, selected or not boolean false
label-position labelPosition The position of the label, relative to the switch graphic 'leading' | 'trailing' 'leading'
form-associated formAssociated boolean true
name name name property for use in conjunction with html forms string

Events

Event name Reactjs attribute Description
tpg-change ontpg-change Event fired when switch state should change

Functions

Name Description Arguments
No functions found.

Slots

Name Description
No slots found.

CSS Parts

Attribute Description
No CSS parts found.

Sandbox