Toggle Icon Button
Use toggle icon buttons for compact, accessible icon-only toggles. Toggle icon buttons combine IconButton accessibility with toggle state management.View source →Use toggle icon buttons for compact, accessible icon-only toggles. Toggle icon buttons combine IconButton accessibility with toggle state management.
This component extends the IconButton component with toggle functionality using Radix UI's Toggle primitive.
Playground
Installation
shellUsage
tsxProps
ToggleIconButton extends all IconButton props with these additional toggle-specific props:
Accessibility Requirements
Like IconButton, toggle icon buttons must have an accessible name. Provide accessibility through one of these methods:
aria-label
Direct descriptive text that explains the button's action.
tsxaria-labelledby
Reference to a label element for more complex descriptions.
tsxControlled 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
ToggleIconButton inherits all IconButton variants. The active state is visually indicated through the data-state="on" attribute.
Solid
Primary toggle actions with strong visual feedback.
tsxSoft
Subtle toggle for content-heavy interfaces.
tsxOutline
Bordered toggle for secondary actions.
tsxGhost
Minimal toggle for utility actions.
tsxSizes
ToggleIconButton supports the same size scale as IconButton.
tsxWith Tooltips
Use the tooltip prop to add context to toggle actions.
tsxPractical Examples
Like Button
tsxFavorite Button
tsxMute Button
tsxPin Button
tsxBold Text Toggle
tsxAccessibility
ToggleIconButton combines IconButton accessibility with toggle state management.
Enforced Accessible Name
Like IconButton, ToggleIconButton throws an error in development if no accessible name is provided.
ARIA Attributes
aria-pressedis automatically set based on the toggle state- Screen readers announce both the button's purpose and pressed state
Live Announcements
State changes are announced to screen readers through live regions, informing users when toggles are activated or deactivated.
Keyboard Navigation
- Full keyboard support with Enter and Space keys
- Focus indicators for all variants
- Proper focus management
Enhancements
IconButton Features
All IconButton features are available, including:
- Built-in tooltip support
- Runtime accessibility validation
- Enhanced loading states
Toggle Features
All toggle features are available, including:
- Controlled and uncontrolled state management
- Live state announcements
- State validation warnings
Combined Accessibility
ToggleIconButton provides the most comprehensive accessibility of all button components:
- Enforced accessible name
- Toggle state announcements
- Tooltip integration
- Screen reader support
Changelog
Added
- Combined IconButton accessibility with toggle functionality
- Live accessibility announcements for state changes
- Controlled and uncontrolled state management
- Full IconButton prop compatibility including tooltips
Changed
- Seamless integration with IconButton component
- Proper ARIA attributes for toggle functionality