Switch
A toggle control enabling users to switch between "on" and "off" states.
Structure
API Reference
The root switch component used to set and manage the state of the switch.
Property | Type | Description |
---|---|---|
checked bindable prop | boolean | Whether or not the switch is checked. Default: false |
onCheckedChange | function | A callback function called when the checked state of the switch changes. Default: undefined |
disabled | boolean | Whether or not the switch is disabled. Default: false |
name | string | The name of the hidden input element, used to identify the input in form submissions. Default: undefined |
required | boolean | Whether or not the switch is required to be checked. Default: false |
value | string | The value of the hidden input element to be used in form submissions when the switch is checked. Default: undefined |
ref bindable prop | HTMLButtonElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The switch's checked state. |
data-checked | —— | Present when the switch is checked. |
data-disabled | —— | Present when the switch is disabled. |
data-switch-root | —— | Present on the root element. |
The thumb on the switch used to indicate the switch's state.
Property | Type | Description |
---|---|---|
ref bindable prop | HTMLSpanElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The switch's checked state. |
data-checked | —— | Present when the switch is checked. |
data-switch-thumb | —— | Present on the thumb element. |