- Docs
- Components
- 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
// 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.
| Prop | Type | Default | What it does |
|---|---|---|---|
label | ReactNode | — | The setting; without one, aria-label is required by its type. |
description | ReactNode | — | A line under the label. |
checked · defaultChecked | boolean | — | 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-slot | Element | What 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.
<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(); }
}}
/>