Skip to main content

Switch

<gstock-switch> | GstockSwitch

API

Properties

Name Description Reflects Type Default
title The title of the switch. Reflects string ''
helpText
help-text
The input’s help text. If you need to display HTML, use the help-text slot instead. string ''
name The name of the switch, submitted as a name/value pair with form data. Reflects string ''
value The current value of the switch, submitted as a name/value pair with form data. Reflects string -
size The size of the switch. Reflects 'small' | 'medium' | 'large' 'medium'
disabled Disables the switch. Reflects boolean false
checked Draws the switch in a checked state. Reflects boolean false
defaultChecked The default value of the form control. Primarily used for resetting the form control. boolean false
form By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work. Reflects string ''
required Makes the switch a required field. Reflects boolean false
validity Gets the validity state object - -
validationMessage Gets the validation message - -
updateComplete

A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties .

Events

Name React Event Description Event Detail
gstock-blur-event onGstockBlurEvent Emitted when the switch loses focus. -
gstock-change-event onGstockChangeEvent Emitted when the checked state changes. -
gstock-focus-event onGstockFocusEvent Emitted when the switch gains focus. -
gstock-input-event onGstockInputEvent Emitted when the switch receives input. -
gstock-invalid-event onGstockInvalidEvent Emitted when the form control has been checked for validity and its constraints aren’t satisfied. -

Learn more about events .

Slots

Name Description
default Content of the switch.

Learn more about slots .

Methods

Name Description
click( ) Simulates a click on the switch.
focus(
options: FocusOptions
)
Sets focus on the switch.
blur( ) Removes focus from the switch.
checkValidity( ) Checks for validity but does not show a validation message. Returns true when valid and false when invalid.
getForm( ) Gets the associated form, if one exists.
reportValidity( ) Checks for validity and shows the browser’s validation message if the control is invalid.
setCustomValidity(
message: string
)
Sets a custom validation message. Pass an empty string to restore validity.

Learn more about methods .

CSS Parts

Name Description
base The component’s base wrapper.
control The container that wraps the control.
thumb The container that wraps the thumb.
label The container that wraps the switch’s label.

Learn more about CSS parts .