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

Setting an aria-label on Toggle or ToggleGroup.Root allows screen readers to announce it, helping users understand the purpose and functionality of the control or group.

<Toggle icon={<LetterBIcon />} aria-label="Toggle bold" />
<ToggleGroup.Root aria-label="Text formatting options">
  <ToggleGroup.Item
    value="bold"
    icon={<LetterBIcon />}
    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>

When combining Toggle with text, set an aria-label that includes the visible text. If omitted, the default aria-label is used, which may cause a mismatch between the text and the accessible name.

Keyboard Navigation

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

ARIA Roles and Attributes

ElementRoles and AttributesUsage
div.ui-toggle__grouprole="group"Indicates that it's a group.
button.ui-toggle__rootaria-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