Switch
Toggle switch control.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import the component from its dedicated entry point to keep the dependency and generated bundle explicit.
tsximport { Switch } from "@tavojs/ui/switch";Normal Tavo.js applications load component styles through the Tavo.js UI plugin. If the application manages component CSS manually, also import @tavojs/ui/css/switch.
When to use
Use it when
Choose something else when
Examples
Switch example
tsximport { Switch } from "@tavojs/ui/switch";
export function SwitchExample1() {
return (
<>
<Switch checked aria-label="Enable alerts" />
</>
);
}Common props and defaults
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
checked | boolean | — | Configures checked for this component. |
defaultChecked | boolean | — | Configures defaultChecked for this component. |
disabled | boolean | — | Configures disabled for this component. |
size | Size | — | Configures size for this component. |
tone | "primary" | "secondary" | "neutral" | — | Configures tone for this component. |
Complete TypeScript API
Import from @tavojs/ui/switch. Published exports: Switch, SwitchProps.
SwitchProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by Switch. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by Switch. |
id | string | No | Inherited id attribute accepted by Switch. |
role | string | No | Inherited role attribute accepted by Switch. |
style | Record<string, unknown> | No | Inherited style attribute accepted by Switch. |
title | string | No | Inherited title attribute accepted by Switch. |
tabIndex | number | No | Inherited tabIndex attribute accepted by Switch. |
hidden | boolean | No | Inherited hidden attribute accepted by Switch. |
disabled | boolean | No | Configures disabled for this component. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by Switch. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by Switch. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by Switch. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by Switch. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by Switch. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by Switch. |
checked | boolean | No | Configures checked for this component. |
defaultChecked | boolean | No | Configures defaultChecked for this component. |
size | Size | No | Configures size for this component. |
tone | "neutral" | "primary" | "secondary" | No | Configures tone for this component. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | Application controlled through checked and the matching callback. |
| DOM target | Native input attributes target the owned form control; wrapper-specific props stay on the documented component root. |
Anatomy and related components
This component exposes one public component root rather than a compound member API.
Limitations
Avoid Switch when wrapping controls without labels or accessible names.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
Renders an input with `role="switch"`.
Renders an input with `role="switch"`.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | forms |
| Component import | @tavojs/ui/switch |
| Explicit CSS import | @tavojs/ui/css/switch |
| Preview | Interactive preview available on this page |