ToggleGroup

A group of toggle buttons where one or more can be selected

Installation#

npmpnpmyarnbun
npx sugarcoat add toggle-group

Examples#

Default#

Default

Single Selection#

Enforce single selection with toggleMultiple={false}.

Single Selection

Multiple Selection#

Multiple

With Icons#

With Icons

Sizes#

Sizes

Colors#

Colors

View Switcher Example#

View Switcher

Disabled Items#

Disabled

Anatomy#

<ToggleGroup>
  <ToggleGroup.Item value="option1">Option 1</ToggleGroup.Item>
  <ToggleGroup.Item value="option2">Option 2</ToggleGroup.Item>
  <ToggleGroup.Item value="option3">Option 3</ToggleGroup.Item>
</ToggleGroup>

Usage#

Import
import { ToggleGroup } from "@sugarcoat/ui-nxt";
Usage
<ToggleGroup 
value={selected} 
onValueChange={setSelected}
toggleMultiple={false}
>
<ToggleGroup.Item value="left">Left</ToggleGroup.Item>
<ToggleGroup.Item value="center">Center</ToggleGroup.Item>
<ToggleGroup.Item value="right">Right</ToggleGroup.Item>
</ToggleGroup>

Props#

ToggleGroup (Root)#

PropTypeDefaultDescription
valuestring[]-Controlled selected values
defaultValuestring[]-Default selected values (uncontrolled)
onValueChange(value: string[]) => void-Callback when selection changes
toggleMultiplebooleantrueWhether multiple items can be selected
itemSize"sm" | "md" | "lg""md"Size variant for all toggle items
itemColor"default" | "primary" | "accent""default"Color variant for all toggle items
itemVariant"outline" | "ghost" | "solid""outline"Style variant for all toggle items
disabledbooleanfalseDisable all items in the group
cssSystemStyleObject-Additional CSS styles using Panda CSS syntax

ToggleGroup.Item#

PropTypeDefaultDescription
valuestring-Unique value for this item
disabledboolean-Whether this item is disabled
size"sm" | "md" | "lg"-Override group size for this item
color"default" | "primary" | "accent"-Override group color for this item
variant"outline" | "ghost" | "solid"-Override group variant for this item

Accessibility#

  • Built on Base UI ToggleGroup for robust accessibility
  • Uses role="group" with proper ARIA attributes
  • Arrow keys navigate between items
  • Space/Enter toggles the focused item
  • Disabled items are properly communicated
  • Use aria-label for icon-only items
Customize Theme
Build your own sugarcoat/ui theme
PresetLime / Violet / Slate
Brand ColorLime
Accent ColorViolet
Gray ScaleSlate
Border RadiusLg