Skip to main content

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.
boolean
The controlled pressed state of the toggle.
boolean
The pressed state when initially rendered (uncontrolled).
(pressed: boolean) => void
Event handler called when the pressed state changes.
boolean
When true, prevents the user from interacting with the toggle.
boolean
default:"false"
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