Skip to main content

Starwind UI v1.12 is now available!

Toggle

Installation

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 emits a starwind-toggle:change event. This can be listened to in order to update the UI based on the event.detail.pressed value. You will likely

Toggle is currently: off

The event emission happens on state change and looks like:

const event = new CustomEvent<ToggleChangeEvent["detail"]>("starwind-toggle:change", {
detail: {
pressed: newState, // boolean
toggleId: this.toggleButton.id,
syncGroup: this.syncGroup,
},
bubbles: true,
cancelable: true,
});
this.toggleButton.dispatchEvent(event);

API Reference

Toggle

An accessible toggle button component with multiple variants and sizes.

PropTypeDefault
variant"default" | "outline""default"
size"sm" | "md" | "lg""md"
defaultPressedbooleanfalse
syncGroupstring-
classstring-
<Toggle variant="outline" size="md" defaultPressed syncGroup="filters">
Toggle filters
</Toggle>

Additional Notes:

  • defaultPressed: Controls the initial pressed/on state of the toggle
  • syncGroup: Optional group key that synchronizes the pressed state across toggles with the same value
  • This component accepts all standard HTML <button> attributes except type and ARIA attributes that are managed internally

Changelog

v1.0.0

  • Initial release with starwind v1.12.0