Toggle
Terminal-style switch component with ON/OFF display.
Import
Basic Usage
Props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Whether the toggle is on (controlled) |
defaultChecked | boolean | false | Default checked state (uncontrolled) |
onCheckedChange | (checked: boolean) => void | — | Callback when state changes |
label | string | — | Label text displayed next to toggle |
disabled | boolean | false | Whether the toggle is disabled |
name | string | — | Name attribute for forms |
className | string | — | Additional CSS class names |
ref | React.Ref<HTMLButtonElement> | — | Forwarded ref to the button element |
With Label
Disabled States
Controlled Toggle
Status: Disabled
Settings Panel Example
Interactive Example
This example shows how toggles can interact with each other:
Keyboard Navigation
| Key | Action |
|---|---|
Space | Toggle state |
Enter | Toggle state |
Tab | Move focus to next element |
Accessibility
- Built on Base UI's accessible switch primitive
- Proper ARIA attributes for screen readers
- Keyboard accessible
- Label properly associated with toggle
Styling
| Variable | Description |
|---|---|
--theme-border | Toggle border color |
--theme-button | Toggle track background when on |
--theme-text | Label color |
--theme-focused-border | Border color when focused |