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
<label appSwitch> ├── [appSwitchLabel] (optional) ├── [appSwitchControl] │ └── [appSwitchThumb] └── <input appSwitchHiddenInput>
Examples
Card Controls
Loading...
Choice Cards
Loading...
Default
Loading...
Invalid
Loading...
Password Protection
Loading...
Share Project
Loading...
Sizes
Loading...
With Description
Loading...
API Reference
<label appSwitch>
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
id | string | undefined | generated | Unique identifier used to create the switch part IDs. |
ids | SwitchElementIds | undefined | — | Overrides the generated IDs for individual parts. |
checked | boolean | undefined | — | Checked state when controlled. Supports Angular two-way binding. |
defaultChecked | boolean | false | Initial checked state when uncontrolled. |
disabled | boolean | false | Disables interaction with the switch. |
invalid | boolean | false | Marks the switch as invalid. |
readOnly | boolean | false | Prevents changes while preserving focus and navigation. |
required | boolean | false | Marks the switch as required. |
name | string | undefined | — | Name used when submitting the switch with a form. |
form | string | undefined | — | Associates the switch with a form by ID. |
label | string | undefined | — | Accessible label used by the switch control. |
value | string | number | undefined | — | Value submitted when the switch is checked. |
size | "sm" | "default" | "default" | Sets the switch's visual size. |
Use [(checked)]="checked" for two-way binding, or combine [checked] with (checkedChange)
when using signals. The directive also implements Angular's ControlValueAccessor for forms
integration.
Outputs
| Output | Type | Description |
|---|---|---|
checkedChange | boolean | undefined | Emits the current checked state. |
checkedDetailsChange | SwitchCheckedChangeDetails | Emits details whenever the checked state changes. |
Context, Providers, and Utilities
| Export | Angular API |
|---|---|
SwitchRootProvider | Directive that provides an externally created switch API through value. |
SwitchContext | Structural directive [switch-context] exposing the root API to a template. |
useSwitch(options?) | Creates the signal-backed switch machine inside an injection context. |
injectSwitchContext() | Injects the nearest switch root context. |
SwitchImports | Readonly collection containing the switch UI and context helpers. |
Types
| Export | Description |
|---|---|
SwitchApi | Connected switch state and actions. |
SwitchElementIds | Overrides for generated switch part IDs. |
SwitchCheckedChangeDetails | Details emitted by checkedDetailsChange. |
UseSwitchOptions | Options accepted by useSwitch. |
UseSwitchProps | Root props accepted by the switch machine. |
UseSwitchReturn | Signal-backed switch machine returned by useSwitch. |
Angular
React
Solid
Svelte
Vue