Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

Installation

Framework Availability

Astro Available React Available

Toggle is available for Astro and React.

Usage

variant

size

syncGroup

Use the syncGroup prop to keep multiple toggles in sync. When one toggle in the group is pressed, all toggles with the same syncGroup will mirror its state.

Event Handling

Whenever toggled, the Toggle root emits starwind:pressed-change. Read the next state from event.detail.pressed.

Toggle is currently: off

Runtime example adjustment

Event listeners now attach to the Toggle root and use starwind:pressed-change; the legacy component-specific event is retained only as a compatibility detail.

API Reference

Styled Component API

These props are added or materially changed by the installed Astro styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Follow the Primitive and Runtime links for lower-level behavior props.

Toggle

Inherits button attributes. Omits `aria-pressed`, `defaultPressed`, `disabled`, `onChange`, `type`, and `value`.

Contains the following additional props:

Prop Type Default Toggle details
defaultPressed boolean
Description
Sets the initial pressed state when the control is uncontrolled.
Classification
Primitive override
Primitive prop
toggle.Root.defaultPressed
nativeButton boolean
Description
Uses native button semantics for the interactive control.
Classification
Primitive override
Primitive prop
toggle.Root.nativeButton
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant
variant "default" | "outline" "default"
Description
Selects the component's visual variant.
Classification
Styled variant

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Toggle.

Primitive API

Runtime API

Toggle primitive
createToggle from @starwind-ui/runtime/toggle

Changelog

v2.0.0

  • Rebuilt Toggle on Starwind Runtime for pressed state and pressed-change events.
  • See the Toggle Primitive for the underlying unstyled anatomy and behavior API.

v1.0.3

  • Refactor tailwind variants functions into separate variants.ts file

v1.0.1

  • Add starwind:init event listener to enable initialization of additional Toggles loaded after an initial page load, such as when using server islands

v1.0.0

  • Initial release with starwind v1.12.0