Toggle

Toggle is a component that has two states: on or off.

Usage

import { Toggle, ToggleGroup } from "@yamada-ui/react"
<Toggle />
<ToggleGroup.Root>
  <ToggleGroup.Item />
</ToggleGroup.Root>

With Text

Change Variant

Change Size

Change Color Scheme

Change Shape

To change the shape, set the rounded prop.

Disable

To disable, set disabled to true.

Read-Only

To read-only, set readOnly to true.

Invalid

To set invalid state, set invalid to true.

Change Invalid Border Color

To change the border color, set errorBorderColor to the color.

Control

Grouping

For multiple selections, set value or defaultValue to an array.

Props

Accessibility

When using only icons in Toggle, set aria-label for the Toggle.

<Toggle icon={<BoldIcon />} aria-label="Toggle bold" />

Setting an aria-label on ToggleGroup.Root allows screen readers to announce the group, helping users understand its purpose.

<ToggleGroup.Root aria-label="Text formatting options">
  <ToggleGroup.Item value="bold" icon={<BoldIcon />} aria-label="Toggle bold" />
  <ToggleGroup.Item
    value="italic"
    icon={<ItalicIcon />}
    aria-label="Toggle italic"
  />
  <ToggleGroup.Item
    value="underline"
    icon={<UnderlineIcon />}
    aria-label="Toggle underline"
  />
</ToggleGroup.Root>

Keyboard Navigation

KeyDescriptionState
TabFocuses the element.-
Space, EnterToggles the focused element.-

ARIA Roles and Attributes

ComponentRole and AttributesUsage
ToggleGroup.Rootrole="group"Indicates that it's a group.
Toggle, ToggleGroup.Itemaria-pressedSet to true if the element is pressed, or false if it is not pressed.
aria-disabledSet to "true" if disabled or readOnly is set.
aria-labelSet value if provided, otherwise default to "Toggle button".
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd
2nd