- components
- ›
- switch
- ›
- svelte
Switch
Toggle between two states, such as on/off.
List
Icons
Direction
API Reference
Root
cursor-pointer data-disabled:cursor-not-allowed data-disabled:opacity-50 inline-flex gap-2 items-center rounded data-focus-visible:outline-2 data-focus-visible:outline-offset-1 data-focus-visible:outline-surface-950-50
Property | Default | Type |
---|---|---|
ids | - | Partial<{ root: string; hiddenInput: string; control: string; label: string; thumb: string; }> | undefinedThe ids of the elements in the switch. Useful for composition. |
label | - | string | undefinedSpecifies the localized strings that identifies the accessibility elements and their states |
disabled | - | boolean | undefinedWhether the switch is disabled. |
invalid | - | boolean | undefinedIf `true`, the switch is marked as invalid. |
required | - | boolean | undefinedIf `true`, the switch input is marked as required, |
readOnly | - | boolean | undefinedWhether the switch is read-only |
onCheckedChange | - | ((details: CheckedChangeDetails) => void) | undefinedFunction to call when the switch is clicked. |
checked | - | boolean | undefinedThe controlled checked state of the switch |
defaultChecked | - | boolean | undefinedThe initial checked state of the switch when rendered. Use when you don't need to control the checked state of the switch. |
name | - | string | undefinedThe name of the input field in a switch (Useful for form submission). |
form | - | string | undefinedThe id of the form that the switch belongs to |
value | "on" | string | number | undefinedThe value of switch input. Useful for form submission. |
dir | "ltr" | "ltr" | "rtl" | undefinedThe document's text/writing direction. |
getRootNode | - | (() => ShadowRoot | Node | Document) | undefinedA root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. |
element | - | Snippet<[HTMLAttributes<"label">]> | undefinedRender the element yourself |
RootProvider
Property | Default | Type |
---|---|---|
value | - | () => SwitchApi<PropTypes> |
element | - | Snippet<[HTMLAttributes<"label">]> | undefinedRender the element yourself |
RootContext
Property | Default | Type |
---|---|---|
children | - | Snippet<[() => SwitchApi<PropTypes>]> |
Control
block preset-filled-surface-200-800 h-6 w-10 p-0.5 rounded-full flex justify-start data-[state=checked]:preset-filled-primary-500
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"span">]> | undefinedRender the element yourself |
Thumb
grid justify-center items-center h-full aspect-square rounded-full bg-surface-50 text-surface-contrast-50 fill-surface-contrast-50 transition-transform duration-100 data-[state=checked]:translate-x-4 rtl:data-[state=checked]:-translate-x-4
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"span">]> | undefinedRender the element yourself |
Label
label-text
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"span">]> | undefinedRender the element yourself |
HiddenInput
Property | Default | Type |
---|---|---|
element | - | Snippet<[HTMLAttributes<"input">]> | undefinedRender the element yourself |