Overview
Toggle provides a button that can be toggled between on and off states. It’s useful for single-option selections like bold, italic, or favorite buttons.Features
- Can be controlled or uncontrolled
- Full keyboard navigation
- Accessible by default with proper ARIA attributes
Installation
Anatomy
API Reference
Root
The toggle component.The controlled pressed state of the toggle.
The pressed state when initially rendered (uncontrolled).
Event handler called when the pressed state changes.
When true, prevents the user from interacting with the toggle.
Change the default rendered element for the one passed as a child.
Example
Accessibility
Uses the button role with
aria-pressed attribute.Keyboard Interactions
- Space - Activates/deactivates the toggle.
- Enter - Activates/deactivates the toggle.
Data Attributes
Root[data-state]- “on” or “off”[data-disabled]- Present when disabled