Search documentation

Search the documentation and open a page.

A control that allows the user to toggle between checked and unchecked states.

Loading...

Installation

pnpm dlx shadcn@latest add @wirekyt/switch

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

InputTypeDefaultDescription
idstring | undefinedgeneratedUnique identifier used to create the switch part IDs.
idsSwitchElementIds | undefined—Overrides the generated IDs for individual parts.
checkedboolean | undefined—Checked state when controlled. Supports Angular two-way binding.
defaultCheckedbooleanfalseInitial checked state when uncontrolled.
disabledbooleanfalseDisables interaction with the switch.
invalidbooleanfalseMarks the switch as invalid.
readOnlybooleanfalsePrevents changes while preserving focus and navigation.
requiredbooleanfalseMarks the switch as required.
namestring | undefined—Name used when submitting the switch with a form.
formstring | undefined—Associates the switch with a form by ID.
labelstring | undefined—Accessible label used by the switch control.
valuestring | number | undefined—Value submitted when the switch is checked.
size"sm" | "default""default"Sets the switch's visual size.

Outputs

OutputTypeDescription
checkedChangeboolean | undefinedEmits the current checked state.
checkedDetailsChangeSwitchCheckedChangeDetailsEmits details whenever the checked state changes.

Context, Providers, and Utilities

ExportAngular API
SwitchRootProviderDirective that provides an externally created switch API through value.
SwitchContextStructural 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.
SwitchImportsReadonly collection containing the switch UI and context helpers.

Types

ExportDescription
SwitchApiConnected switch state and actions.
SwitchElementIdsOverrides for generated switch part IDs.
SwitchCheckedChangeDetailsDetails emitted by checkedDetailsChange.
UseSwitchOptionsOptions accepted by useSwitch.
UseSwitchPropsRoot props accepted by the switch machine.
UseSwitchReturnSignal-backed switch machine returned by useSwitch.