ComponentStandalone

Switch

Boolean toggle with an iOS-style slider. A signal-forms native control — it implements FormCheckboxControl, so [formField] binds straight to its checked model. [(checked)] works standalone, and [(ngModel)] / reactive forms keep working through Angular 22's forms bridge.

Installation

import { WrSwitch } from 'ngwr/switch';

@Component({ imports: [WrSwitch, FormsModule] })
export class MyComponent {}

Basic usage

Value: true
<wr-switch [(checked)]="enabled">Notifications</wr-switch>

Disabled

<wr-switch [disabled]="true">Disabled</wr-switch>

API

NameDescriptionTypeDefault
ariaLabelAccessible name for a switch used WITHOUT projected text. The wrapping <label> names the control whenever content is projected; with none, the label is empty and the input has no name at all.string | nullnull
idStable id used to associate the native input with its label. Lands on the inner <input>; the host never keeps it.stringrandomId('wr-switch')
disabledDisable the switch. Bound automatically from the field's disabled state when used with [formField].booleanfalse
readonlyRefuse edits while staying focusable and submittable. Bound automatically from the field's readonly state when used with [formField]. A native checkbox ignores the readonly attribute, so this cancels the click's activation behaviour instead — which covers Space too, since the key arrives as a click — and mirrors the state as aria-readonly, which role switch supports.booleanfalse
sizeControl size — shares the --wr-control-* contract. Unset falls back to the switch.size app default from provideWrConfig().WrSwitchSize | null'md'
checkedOn / off state. Bound by [formField], or two-way via [(checked)].booleanfalse
(touch)Emitted on blur so a bound field can mark itself touched.void

CSS variables

Custom properties ngwr/switch publishes. Each default below is declared on the component's own selector, so a :root override is shadowed by it — set them on that selector, on a wrapper you scope yourself, or inline on the element. Unlike the BEM class names, these are the supported way to restyle the component.

VariableDefaultDeclared on
--wr-switch-bgvar(--wr-color-outline).wr-switch +1 variant override
--wr-switch-bg-checkedvar(--wr-color-primary).wr-switch
--wr-switch-colorvar(--wr-color-on-surface).wr-switch +1 variant override
--wr-switch-font-sizevar(--wr-text-sm).wr-switch +2 variant overrides
--wr-switch-line-heightvar(--wr-control-line-height-md).wr-switch +2 variant overrides
--wr-switch-thumbvar(--wr-color-surface).wr-switch
--wr-switch-thumb-size0.875rem.wr-switch +2 variant overrides
--wr-switch-track-height1.125rem.wr-switch +2 variant overrides
--wr-switch-track-width2rem.wr-switch +2 variant overrides