import { Switch } from "@senvenli/react/selection";
export default function Example() {
return <Switch defaultSelected>Online orders</Switch>;
}import { Switch } from "@senvenli/react/selection";Examples
Saved by the app
Controlled, with a description that reports the state.import { Switch } from "@senvenli/react/selection";
import { useState } from "react";
export default function Example() {
const [isOn, setIsOn] = useState(false);
return (
<Switch isSelected={isOn} onChange={setIsOn} description={isOn ? "A summary is sent every Monday at 9:00." : "No summary is sent."}>
Weekly summary email
</Switch>
);
}Disabled
A setting that cannot change, on and off.import { Stack } from "@senvenli/react/layout";
import { Switch } from "@senvenli/react/selection";
export default function Example() {
return (
<Stack space="space-150">
<Switch isDisabled defaultSelected description="Required for every member of this workspace.">
Two-step sign-in
</Switch>
<Switch isDisabled description="Available on the Business plan.">
Audit log
</Switch>
</Stack>
);
}Sizes
`size` small, medium (default) or large.import { Stack } from "@senvenli/react/layout";
import { Switch } from "@senvenli/react/selection";
export default function Example() {
return (
<Stack space="space-150">
<Switch size="small" defaultSelected>
Small
</Switch>
<Switch defaultSelected>Medium</Switch>
<Switch size="large" defaultSelected>
Large
</Switch>
</Stack>
);
}Guidelines
When to use it
- A setting that applies at once.
Use something else when
- The choice is submitted with a form. Checkbox
Do and avoid
- Name the setting by its on-state ("Online orders"), never "On/Off".
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Space | Toggles it. |
Built in
- Announced as a switch with its state; a busy state while saving.
You provide
- A label naming the setting.
API reference
Switch
| Prop | Type | Default | Description |
|---|---|---|---|
size | ComponentSize | – |
|
childrenRequired | React.ReactNode | – | The setting, named as its on-state ("Online orders"), never "On/Off". |
isSelected | boolean | – | |
defaultSelected | boolean | – | |
onChange | (isSelected: boolean) => void | – | |
description | React.ReactNode | – | |
isDisabled | boolean | – | |
name | string | – | |
aria-busy | boolean | "true" | "false" | – | Marks a pending change ("saving"): |
sizeComponentSizesmall,medium(default) orlarge; the provider default otherwise.childrenRequiredReact.ReactNodeThe setting, named as its on-state ("Online orders"), never "On/Off".
isSelectedbooleandefaultSelectedbooleanonChange(isSelected: boolean) => voiddescriptionReact.ReactNodeisDisabledbooleannamestringaria-busyboolean | "true" | "false"Marks a pending change ("saving"):
aria-busyon the switch control itself, therole="switch"input, where screen readers read it. It does not lock the switch: it still toggles unlessisDisabledis set too. Left out, the DOM is unchanged. It is applied after hydration (in a layout effect, as React Aria does not forward it), so server-rendered HTML does not carry it; it appears on the first client render.