Loading...
Installation
Install the following dependencies:
Copy and paste the following code into your project.
Loading...
Update the import paths to match your project setup.
Composition
Switch ├── SwitchLabel (optional) ├── SwitchControl │ └── SwitchThumb └── SwitchHiddenInput
Examples
Card Controls
Loading...
Choice Cards
Loading...
Default
Loading...
Invalid
Loading...
Password Protection
Loading...
Share Project
Loading...
Sizes
Loading...
With Description
Loading...
API Reference
Switch
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | — | Unique identifier used to connect the component parts. |
ids | ElementIds | undefined | — | Overrides generated identifiers for individual parts. |
label | string | undefined | — | Configures label. |
disabled | boolean | undefined | false | Disables interaction with the component. |
invalid | boolean | undefined | — | Marks the associated form control as invalid. |
required | boolean | undefined | false | Marks the associated form control as required. |
readOnly | boolean | undefined | false | Prevents changes while preserving focus and navigation. |
onCheckedChange | ((details: CheckedChangeDetails) => void) | undefined | — | Runs when checked changes. |
checked | boolean | undefined | — | Checked state when the component is controlled. |
defaultChecked | boolean | undefined | — | Initial checked state when the component is uncontrolled. |
name | string | undefined | — | Name used when submitting the value with a form. |
form | string | undefined | — | Associates the control with a form by ID. |
value | string | number | undefined | — | Current value when the component is controlled. |
Context, Hooks, and Types
| Export | API |
|---|---|
SwitchContext | Render-prop component that exposes component state and actions. |
SwitchRootProvider | Provides an externally created API to the component tree. |
useSwitch | Creates or accesses the component API. |
useSwitchContext | Returns the nearest component API. |
SwitchCheckedChangeDetails | Type for the details object passed to the matching change callback. |
Angular
React
Solid
Svelte
Vue