Toggle

A two-state button that can be either on or off.

Features

    Full keyboard navigation.

    Can be controlled or uncontrolled.

Installation

Install the component from your command line.

npm install @tealess/toggle

Anatomy

Import the component.

import * as Toggle from "@tealess/toggle";
export default () => <Toggle.Root />;

API Reference

Root

The toggle.

PropTypeDefault
asChild
boolean
false
defaultPressed
boolean
No default value
pressed
boolean
No default value
onPressedChange
function
No default value
disabled
boolean
No default value
Data attributeValues
[data-state]"on" | "off"
[data-disabled]

Present when disabled

Accessibility

Keyboard Interactions

KeyDescription
Space
Activates/deactivates the toggle.
Enter
Activates/deactivates the toggle.
PreviousToast