Skip to main content
  1. Docs
  2. Components
  3. Forms

Switch

A setting, on or off, applied at once. A setting that waits for Save is a Checkbox.

Import
@qeetrix/react
Status
StableSince 0.0.2
Renders
<span role="switch">Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

switch.tsx
// From the package: a build keeps only what it uses.
import { Switch } from "@qeetrix/react";

// Or from its own path.
import { Switch } from "@qeetrix/react/switch";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
labelReactNode—The setting; without one, aria-label is required by its type.
descriptionReactNode—A line under the label.
checked · defaultCheckedboolean—On, controlled or to start with.
onCheckedChange(checked, details) => void—Called as it switches: save here.
name · value · disabled · readOnly · required…—As on a form control.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat it is
switch<div>The row.
switch-track<span role="switch">The track: ref and Base UI props land here.
switch-thumb<span>The thumb.

04

Save as it switches

Roll back if the save fails, and say so.

mfa.tsx
<Switch
  label="Two-step sign-in for everyone"
  checked={policy.mfa}
  onCheckedChange={async (next) => {
    setPolicy({ ...policy, mfa: next });
    try { await savePolicy({ mfa: next }); showSaved(); }
    catch { setPolicy(policy); showSaveFailed(); }
  }}
/>
Next — SwitchAccessibility