Navigated to /docs/ui/components/toggle

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.

TSX
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

Use Toggle for an action that remains on or off, such as bold formatting, pinning, muting, or showing a layer.

Choose something else when

Use Checkbox or Switch for form settings, Button for one-time actions, and Tabs for switching content panels.

Examples

Toggle example

TSX
tsximport { Toggle } from "@tavojs/ui/toggle";

export function ToggleExample1() {
  return (
    <>
      <Toggle pressed>Preview</Toggle>
    </>
  );
}

Common props and defaults

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
asstring | Component<Record<string, unknown>>

Changes the rendered root element or component while preserving Tavo.js UI styling and public props.
pressedboolean

Configures pressed for this component.
sizeSize

Configures size for this component.
variant"default" | "outline" | "ghost"

Configures variant for this component.
hrefstring

Configures href for this component.

Complete TypeScript API

Import from @tavojs/ui/toggle. Published exports: Toggle, ToggleProps, ToggleVariant.

ToggleProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by Toggle.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by Toggle.

idstring

No

Inherited id attribute accepted by Toggle.

rolestring

No

Inherited role attribute accepted by Toggle.

styleRecord<string, unknown>

No

Inherited style attribute accepted by Toggle.

titlestring

No

Inherited title attribute accepted by Toggle.

tabIndexnumber

No

Inherited tabIndex attribute accepted by Toggle.

hiddenboolean

No

Inherited hidden attribute accepted by Toggle.

disabledboolean

No

Inherited disabled attribute accepted by Toggle.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by Toggle.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by Toggle.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by Toggle.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by Toggle.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by Toggle.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by Toggle.

asPolymorphicAs

No

Changes the rendered root element or component while preserving Tavo.js UI styling and public props.

pressedboolean

No

Configures pressed for this component.

sizeSize

No

Configures size for this component.

variantToggleVariant

No

Configures variant for this component.

hrefstring

No

Configures href for this component.

State ownership and DOM target

ConcernContract
StateApplication controlled through pressed and the matching callback.
DOM targetThe 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

ContractCurrent value
Maturitystable
Categoryforms
Component import@tavojs/ui/toggle
Explicit CSS import@tavojs/ui/css/toggle
PreviewInteractive preview available on this page