Toggle
Button with an application-controlled pressed/unpressed state.
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 { Toggle } from "@tavojs/ui/toggle";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/toggle.
When to use
Use it when
Choose something else when
Examples
Toggle example
tsximport { Toggle } from "@tavojs/ui/toggle";
export function ToggleExample1() {
return (
<>
<Toggle pressed>Preview</Toggle>
</>
);
}Common props and defaults
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
as | string | Component<Record<string, unknown>> | — | Changes the rendered root element or component while preserving Tavo.js UI styling and public props. |
pressed | boolean | — | Configures pressed for this component. |
size | Size | — | Configures size for this component. |
variant | "default" | "outline" | "ghost" | — | Configures variant for this component. |
href | string | — | Configures href for this component. |
Complete TypeScript API
Import from @tavojs/ui/toggle. Published exports: Toggle, ToggleProps, ToggleVariant.
ToggleProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by Toggle. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by Toggle. |
id | string | No | Inherited id attribute accepted by Toggle. |
role | string | No | Inherited role attribute accepted by Toggle. |
style | Record<string, unknown> | No | Inherited style attribute accepted by Toggle. |
title | string | No | Inherited title attribute accepted by Toggle. |
tabIndex | number | No | Inherited tabIndex attribute accepted by Toggle. |
hidden | boolean | No | Inherited hidden attribute accepted by Toggle. |
disabled | boolean | No | Inherited disabled attribute accepted by Toggle. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by Toggle. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by Toggle. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by Toggle. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by Toggle. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by Toggle. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by Toggle. |
as | PolymorphicAs | No | Changes the rendered root element or component while preserving Tavo.js UI styling and public props. |
pressed | boolean | No | Configures pressed for this component. |
size | Size | No | Configures size for this component. |
variant | ToggleVariant | No | Configures variant for this component. |
href | string | No | Configures href for this component. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | Application controlled through pressed and the matching callback. |
| DOM target | The public root follows the as/component prop. Root attributes, className, style, and supported events are forwarded there. |
Anatomy and related components
This component exposes one public component root rather than a compound member API.
Limitations
Use Checkbox or Switch for form settings, Button for one-time actions, and Tabs for switching content panels.
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
Emits `aria-pressed`.
Emits `aria-pressed`.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | forms |
| Component import | @tavojs/ui/toggle |
| Explicit CSS import | @tavojs/ui/css/toggle |
| Preview | Interactive preview available on this page |