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".

Similar Components

Checkbox

Checkbox is a component used for allowing users to select multiple values from multiple options.

NativeSelect

NativeSelect is a component used for allowing users to select one value from a list of options. It displays a native dropdown list provided by the browser (user agent).

Radio

Radio is a component used for allowing users to select one option from multiple choices.

Rating

Rating is a component used to allow users to provide ratings.

SegmentedControl

SegmentedControl is a component used for allowing users to select one option from multiple choices.

Switch

Switch is a component used to toggle between on and off states.

CheckboxCard

CheckboxCard is a component used for allowing users to select multiple values from multiple options.

FileButton

FileButton is a button component used for users to select files.

Uses Components & Hooks