// preview in
saved for every page

Toggle

A button that stays pressed, such as Bold in an editor. ToggleGroup joins several, with one or many pressed and arrow-key navigation.

Built on Base UIPattern WAI-ARIA Button (aria-pressed)Client componentSource ↗
minimal · light · #3fa34d
defaultPressed
disabled

Installation

Set up Camaleo once (Installation), then import what you need.

import { Toggle, ToggleGroup } from "@camaleo/react";

Anatomy

A Toggle is one button with aria-pressed. A ToggleGroup wraps several and moves focus between them with the arrow keys.

BIU
[data-slot="toggle-group"][data-slot="toggle"][data-pressed]icon or label (children)

Examples

minimal · light · #3fa34d

With a label

An icon and a short label. The label names the setting, not the state.

Notifications are on.

Controlled

Click it. pressed and onPressedChange let the rest of the screen react to the state.

One of many

A ToggleGroup lets only one stay pressed, like text alignment. Arrow keys move between the options.

Many of many

With multiple, any number can be pressed — bold, italic and underline at once.

Icon only, with a tooltip

The aria-label is the tooltip text, so screen readers hear the same name sighted users see on hover.

Disabled

Keeps its pressed state visible, so people still see what is on.

In context

Release notes

Bold and alignment stay pressed while the cursor is in formatted text.

Editor toolbarToggleGroup · Toggle · Separator

Projects

Atlas
Borealis
Cirrus
View switcherToggleGroup · Card

Atlas

Updated 2 hours ago

FavoriteToggle · Card

Guidelines

DoKeep the label the same.

The pressed look carries the state; screen readers announce it from aria-pressed.

Don’tA toggle for a one-off action.

"Send" happens once. Use a Button.

DoGroup related options.

A ToggleGroup gives them one tab stop and arrow-key navigation.

Don’tLoose toggles that should be exclusive.

Two alignments pressed at once is a state that makes no sense.

Props

PropTypeDefaultDescription
pressedboolean—Whether the toggle button is currently pressed. This is the controlled counterpart of defaultPressed.
defaultPressedbooleanfalseWhether the toggle button is currently pressed. This is the uncontrolled counterpart of pressed.
disabledbooleanfalseWhether the component should ignore user interaction.
onPressedChangefunction—Callback fired when the pressed state is changed.
valuestring—A unique string that identifies the toggle when used inside a toggle group.
renderReactElement | (props, state) => ReactElement—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
Also accepts every prop of the underlying primitive and native attributes.

ToggleGroup takes value, defaultValue and onValueChange (arrays of the toggles' value), multiple and orientation.

Styling hooks

Attributes

data-slot"toggle" · "toggle-group"
data-pressedpresent while pressed
data-disabledpresent when disabled
aria-pressed"true" · "false"

Tokens it reads

Color

--cml-border--cml-button-disabled-shadow--cml-button-outline-bg--cml-button-outline-border--cml-button-outline-shadow--cml-fg--cml-fg-secondary--cml-focus-offset--cml-focus-ring--cml-focus-width--cml-shadow-control-active--cml-surface--cml-surface-raised

Shape & size

--cml-border-width--cml-control-height--cml-control-padding--cml-gap--cml-radius-control--cml-radius-control-sm

Type & motion

--cml-duration-fast--cml-ease-standard--cml-font-control--cml-font-size-control--cml-font-size-control-sm--cml-font-weight-control--cml-letter-spacing-control--cml-press-translate--cml-text-transform-control

This component only

--cml-disabled-opacity--cml-toggle-pressed-bg--cml-toggle-pressed-fg--cml-toggle-pressed-shadow

Accessibility

SpacePresses or releases the toggle.
EnterPresses or releases the toggle.
Arrow keysIn a ToggleGroup, move focus to the previous or next toggle.
Home / EndIn a ToggleGroup, move focus to the first or last toggle.
Was this page helpful? · Edit this page on GitHub