Toggle Button
Use toggle buttons for actions that can be pressed or unpressed. Toggle buttons provide proper accessibility announcements and state management for binary states.View source →Use toggle buttons for actions that can be pressed or unpressed. Toggle buttons provide proper accessibility announcements and state management for binary states.
This component extends the Button component with toggle functionality using Radix UI's Toggle primitive.
Playground
Installation
shellUsage
tsxProps
ToggleButton extends all Button props with these additional toggle-specific props:
Controlled vs Uncontrolled
Uncontrolled
Use defaultPressed to set an initial state without managing it yourself.
tsxControlled
Use pressed and onPressedChange for full control over the toggle state.
tsxVariants
ToggleButton inherits all Button variants. The active state is visually indicated through the data-state="on" attribute.
Solid
Primary toggle actions.
tsxSoft
Subtle toggle for content-heavy interfaces.
tsxOutline
Bordered toggle for secondary actions.
tsxGhost
Minimal toggle for utility actions.
tsxColors
Use semantic colors to communicate the toggle's purpose.
tsxSizes
ToggleButton supports the same size scale as Button.
tsxWith Icons
Combine icons with text for clearer toggle actions.
tsxPractical Examples
Bookmark Button
tsxFollow Button
tsxMute Button
tsxAccessibility
ToggleButton provides comprehensive accessibility support.
ARIA Attributes
aria-pressedis automatically set based on the toggle state- Screen readers announce the button's pressed state
Live Announcements
State changes are announced to screen readers through live regions, ensuring users are informed of toggle actions.
Keyboard Navigation
- Full keyboard support with Enter and Space keys
- Focus indicators for all variants
- Proper focus management
Enhancements
Live State Announcements
ToggleButton announces state changes to screen readers, helping users understand when a toggle has been activated or deactivated.
State Validation
Development warnings are provided when toggle state may not be functioning correctly, helping catch issues early.
Button Integration
Full access to all Button props including variants, sizes, colors, and loading states.
Changelog
Added
- Live accessibility announcements for state changes
- Controlled and uncontrolled state management
- State validation warnings in development
- Full Button prop compatibility
Changed
- Seamless integration with Button component
- Proper ARIA attributes for toggle functionality