ToggleButton
A toggle button component that supports pressed/unpressed states with optional icon morphing and label animations.Import
Props
Icon to display when not pressed.
Icon to display when pressed. Falls back to
icon if not provided.Label to display when not pressed.
Label to display when pressed. Falls back to
children if not provided.The visual style variant.Options:
tertiary- Glass-like appearance with shadow and blur (default)ghost- Transparent background, visible on hoversecondary- Subtle gray background
The size of the button.Options:
xs- 28px height/width (var(—space-28))s- 32px height/width (var(—space-32))m- 36px height/width (var(—space-36))l- 40px height/width (var(—space-40))
Color tone applied when pressed.Feedback tones:
default,info,warning,danger,success
red,orange,amber,yellow,lime,green,emeraldteal,cyan,sky,blue,indigo,violet,purplefuchsia,pink,rose
Enable morphing animation between icons (blur, scale, y-position). When false, uses a smooth fade transition.
Controlled pressed state. When provided, the component becomes controlled.
Default pressed state for uncontrolled usage.
Callback fired when the pressed state changes.
Fixed width in pixels for label animation (unpressed state). Enables smooth width transitions.
Fixed width in pixels for label animation (pressed state).
When true, disables interaction and applies disabled styling.
Additional CSS classes to apply to the button.
Explicit escape hatch for intentional structural overrides.
Usage
Icon-Only Toggle
With Label
Variants
Sizes
With Pressed Tone
Icon Morph Animation
Changing Labels
Animated Label Width
Controlled Toggle
Uncontrolled with Default
Animation
ToggleButton includes two animation modes:Fade Mode (default)
Smooth opacity transition between icons:- Duration: 150ms
- Easing: ease-out
- No morphing effects
Morph Mode
Dynamic icon transformation with:- Y-axis translation: 8px
- Scale: 0.5 to 1.0
- Blur: 0 to 8px
- Spring animation: bounce 0.2, duration 250ms
labelWidth is provided.
All animations respect prefers-reduced-motion and become instant transitions.
Accessibility
- Built on Base UI’s
Toggleprimitive with ARIA support - When using icon-only, always provide
aria-label - Focus ring uses utility-focus-inner and utility-focus-outer
- Active state includes subtle scale animation (0.98)
- Pressed state is communicated via
aria-pressedattribute - Disabled state uses
cursor-not-allowedand reduced opacity
Design Tokens
The ToggleButton component uses the following design tokens: Colors:actions-tertiary-default,actions-tertiary-hover,actions-tertiary-disabledactions-secondary-default,actions-secondary-hover,actions-secondary-disabledcontent-strong,content-subtle,content-disabled
- Heights/widths:
space-28,space-32,space-36,space-40 - Horizontal padding:
space-10,space-12,space-16 - Gap between elements:
space-2,space-4 - Icon sizes:
space-16,space-18 - Label padding:
space-4,space-6
- Border radius:
radius-max - Font weight:
font-weight-medium - Focus ring:
utility-focus-inner,utility-focus-outer - Shadows (tertiary):
utility-shadow-l1,utility-shadow-l2,utility-shadow-l3