- components
 - ›
 - switch
 - ›
 - react
 
Switch
Toggle between two states, such as on/off.
Checked Color
Use the Tailwind data attribute syntax to target the active state using data-[state=checked]
List
Icons
Direction
API Reference
Root
| Property | Default | Type | 
|---|---|---|
 ids  |  - |    Partial<{ root: string; hiddenInput: string; control: string; label: string; thumb: string; }> | undefined The 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  |  - |    ((attributes: HTMLAttributes<"label">) => Element) | undefinedRender the element yourself  |  
RootProvider
| Property | Default | Type | 
|---|---|---|
 value  |  - |    SwitchApi<PropTypes>  |  
 element  |  - |    ((attributes: HTMLAttributes<"label">) => Element) | undefinedRender the element yourself  |  
RootContext
| Property | Default | Type | 
|---|---|---|
 children  |  - |    (switch_: SwitchApi<PropTypes>) => ReactNode  |  
Control
| Property | Default | Type | 
|---|---|---|
 element  |  - |    ((attributes: HTMLAttributes<"span">) => Element) | undefinedRender the element yourself  |  
Thumb
| Property | Default | Type | 
|---|---|---|
 element  |  - |    ((attributes: HTMLAttributes<"span">) => Element) | undefinedRender the element yourself  |  
Label
| Property | Default | Type | 
|---|---|---|
 element  |  - |    ((attributes: HTMLAttributes<"span">) => Element) | undefinedRender the element yourself  |  
HiddenInput
| Property | Default | Type | 
|---|---|---|
 element  |  - |    ((attributes: HTMLAttributes<"input">) => Element) | undefinedRender the element yourself  |