Skip to main content

Starwind UI v3.7 is here with stable Vue and Svelte, the new Chart component, and full RTL support. Read the release notes

Toggle Group

Installation

Usage

Composition

Place each toggle item inside the group:

ToggleGroup
├── ToggleGroupItem
└── ToggleGroupItem

Sizes

ToggleGroup is the sole size owner. Set size="sm", size="md" (the default), or size="lg" on the root; items still support independent variant overrides but no longer accept size.

Size Migration

BeforeAfter
<ToggleGroup><ToggleGroupItem size="sm" /></ToggleGroup><ToggleGroup size="sm"><ToggleGroupItem /></ToggleGroup>

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Toggle Group

Inherits div attributes. Omits `defaultValue` and `onChange`.

Contains the following additional props:

Prop Type Default Toggle details
defaultValue string[] —
Description
Sets the initial value when the component is uncontrolled.
Classification
Primitive override
Primitive prop
toggle-group.Root.defaultValue
loopFocus boolean —
Description
Wraps keyboard focus from the last item to the first and vice versa.
Classification
Primitive override
Primitive prop
toggle-group.Root.loopFocus
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Wrapper prop
spacing number 2
Description
Sets the space between grouped controls.
Classification
Wrapper prop
variant "default" | "outline" "default"
Description
Selects the component's visual variant.
Classification
Wrapper prop

Toggle Group Item

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
variant "default" | "outline" —
Description
Selects the component's visual variant.
Classification
Wrapper prop

Primitive And Runtime API

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

Runtime API

Toggle primitive
createToggle from @starwind-ui/runtime/toggle
Toggle Group primitive
createToggleGroup from @starwind-ui/runtime/toggle-group

Changelog

View version history v2.2.0 6 releases

v2.2.0

  • Toggle Group arrow keys follow visible horizontal order in RTL, including inside a section with its own dir.
  • In Vue, this component now needs Vue 3.5.21 or newer.
  • Internal code cleanup, such as unused code and import order. This cleanup does not change behavior.

v2.1.0

  • In Svelte, a defined value, or a defined pressed on an item, that you pass when ToggleGroup mounts now stays under your control, as in React and Vue. To change it, use bind: or update your state in the change callback. A form reset keeps it. If you pass undefined at mount, ToggleGroup keeps its own state.
  • In Vue, a Boolean prop that you leave out, such as loopFocus or nativeButton, no longer becomes false. The default of the underlying component applies.
  • Fixed a ToggleGroup trigger on a link or span that stayed disabled when a framework wrote disabled="false". On a native form control, any disabled attribute still disables it.

v2.0.2

  • React toggles now use the group’s selected and disabled state before the page becomes interactive.

v2.0.1

  • The default export in index.ts now has a name, ToggleGroupParts, so framework tools show a clear name.

v2.0.0

  • Removed size from ToggleGroupItem. Set size on ToggleGroup for all of its items.
  • Migration: move every item-level size value to its containing ToggleGroup. Per-item variant overrides continue to work.

v1.0.0

  • Added Toggle Group. It gets its behavior from Starwind Runtime, and the group holds the pressed state of its toggles.
  • See the Toggle Primitive and Toggle Group Primitive for the unstyled parts and the behavior API.