AppSwitch
A single on/off toggle that takes effect the moment it flips — no Save button.
<app-switch label="Email notifications" name="email-notif" />A switch flips a single setting on or off, and the change applies immediately — dark mode, email notifications, a live feature flag. That instant, no-Save mental model is what separates a switch from a checkbox: a checkbox waits for the form to submit, a switch acts the moment it moves.
Its look comes entirely from the shared @webority/theme, so the Razor <app-switch> and the React <AppSwitch> render identically — a switch is a switch on every Webority surface.
Playground
Every attribute, live. Each change re-renders the real tag helper on the server, so the markup underneath is the exact call that produced the switch above it.
error shows — it also flips aria-invalid to true. Clear the error text in the playground to see the hint reappear.On and off
Bind checked / onChange to a boolean; the switch reflects it and reports every flip. Pair it with a caption so the user reads what the toggle controls.
Show code
<app-switch label="Email notifications" name="email-notif" checked="true" />
Default state
Set the starting position with the checked attribute — present (or "true") renders the switch already on, omitted renders it off.
Show code
<app-switch label="Auto-renew" name="auto-renew" checked="true" /> <app-switch label="Beta features" name="beta-features" />
Shape
shape takes round (the default sliding pill, truly circular ends), pill (the same sliding pill with squircle ends, the checkbox corner shape), or circle, a compact round on/off button that flips colour in place rather than sliding a knob.
Show code
<app-switch label="Auto-renew" name="auto-renew" checked="true" /> <app-switch label="Auto-renew" name="auto-renew" shape="pill" checked="true" /> <app-switch label="Auto-renew" name="auto-renew" shape="circle" checked="true" />
Validation
Show a hint for guidance and an error when validation fails. They share one slot below the control — the error replaces the hint, matching app-input.
Show code
<app-switch label="Email notifications" name="email-notif" hint="You can change this later." /> <app-switch label="Email notifications" name="email-notif" error="Notifications are required for this plan." />
When to use
Use it when
- A single on/off setting that takes effect immediately.
- Toggling a live feature or preference — dark mode, notifications, a feature flag.
- A binary state where "instant" is the mental model, not "save later".
Reach for something else when
- The opt-in is saved with the rest of a form. → AppCheckbox
- The user picks one of several exclusive options. → AppRadio
- It triggers an action rather than holding a state. → AppButton
- The user selects several values from a list. → AppMultiSelect
Best practices
Every option
The whole surface of the component, one cell per value.
shape — all three
shape="round"
shape="pill"
shape="circle"
checked state
(default) uncheckedchecked="true"disabled
disabled (unchecked)disabled checked="true"label
(no label)label="Auto-renew"child content — rich markup labelrequired
required="true"validation — hint, error, and error winning over hint
hint="You can change this later."error="Notifications are required for this plan."hint + error together — error winsAttributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| label | string | — | The visible label rendered beside the switch. Rich markup (a link, emphasis) can be written as child content instead — it renders unencoded, matching React's ReactNode label. |
| name | string | — | Field name for form submission; also derives the input id when id is not set. |
| id | string | — | Explicit input id — binds the label's for to it and overrides the name-derived id. Declared property, matching React's id. |
| value | string | — | Submitted value when on. |
| checked | bool | false | Renders the switch in the on position. |
| shape | round | pill | circle | round | Track shape: round is the sliding pill with truly circular ends; pill is the same sliding pill with squircle ends; circle is a compact round on/off button. |
| disabled | bool | false | Disables the switch. Declared property, matching React's disabled. |
| required | bool | false | Marks the input as required. Also a pass-through attribute, not a bound property. |
| error | string | — | Error message below the control. Turns aria-invalid true and replaces the hint. |
| hint | string | — | Helper text below the control. Hidden while an error is shown. |
| asp-for | ModelExpression | — | Razor-only. Binds name, id, checked state, label and validation message from a Razor Pages model property — the nearest equivalent to React's controlled checked/onChange pair. |