Skip to Content
⭐️ Leave a star →
ComponentsToggle

Toggle

A two-state pressable button — renders as a <button> with aria-pressed and data-state="on"|"off". Use it standalone, or drop several inside ToggleGroup.Root (single or multiple selection) for a segmented control or formatting pill bar. Distinct from Switch, which is a settings on/off control.

Features

Renders as a button with aria-pressed and data-state.
Works standalone (controlled or uncontrolled) or inside a ToggleGroup.
ToggleGroup supports single (one active) or multiple selection.
Roving-tabindex focus with arrow-key navigation inside a group.
Horizontal or vertical orientation; optional focus looping.
Supports disabled state per toggle or for the whole group.

Example

The quick brown fox jumps over the lazy dog.

import { Toggle, ToggleGroup } from '@wire-ui/react' // Standalone <Toggle defaultPressed aria-label="Toggle italic"> <i>I</i> </Toggle> // Grouped (multiple selection) <ToggleGroup.Root type="multiple" defaultValue={['bold']} aria-label="Text formatting"> <Toggle value="bold" aria-label="Bold"><b>B</b></Toggle> <Toggle value="italic" aria-label="Italic"><i>I</i></Toggle> <Toggle value="underline" aria-label="Underline">U</Toggle> </ToggleGroup.Root>

Styling

Toggle exposes data-state ("on" / "off") plus the standard interactive-state attributes from useInteractiveState. Use these to style the pressed appearance and focus ring.

<Toggle className=" text-black data-[state=on]:bg-black data-[state=on]:text-white data-[disabled]:opacity-40 data-[disabled]:cursor-not-allowed data-[focus-visible]:ring-2 data-[focus-visible]:ring-black "> <b>B</b> </Toggle>

ToggleGroup.Root exposes data-orientation so a single group can flip between row and column layouts:

<ToggleGroup.Root className=" inline-flex gap-1 data-[orientation=vertical]:flex-col data-[disabled]:opacity-50 " />

Using data attributes

Toggle sets data-state ("on" / "off") and data-disabled. ToggleGroup.Root sets data-orientation and data-disabled.

/* Pressed toggle */ [data-state="on"] { background: #000; color: #fff; } [data-state="off"] { /* default */ } /* Disabled */ [data-disabled] { opacity: 0.4; cursor: not-allowed; } /* Vertical group */ [data-orientation="vertical"] { flex-direction: column; }

Toggle props

PropTypeDefaultDescription
pressedbooleanControlled pressed state (standalone use)
defaultPressedbooleanfalseInitial pressed state (uncontrolled, standalone use)
onPressedChange(pressed: boolean) => voidCalled when the pressed state changes (standalone use)
valuestringIdentity within a ToggleGroup.Root. When set inside a group, the group owns the pressed state
disabledbooleanfalseDisables this toggle

Also accepts all native <button> attributes (except value and onChange).

ToggleGroup.Root props (single)

PropTypeDefaultDescription
type'single'requiredOne toggle active at a time
valuestring | nullControlled selected value (null when none)
defaultValuestring | nullInitial selected value (uncontrolled)
onChange(value: string | null) => voidCalled when the selection changes
disabledbooleanfalseDisable the whole group
orientation'horizontal' | 'vertical''horizontal'Layout + arrow-key axis
loopbooleantrueWrap arrow-key focus from last → first
rovingFocusbooleantrueManage focus as a single tab stop with arrow-key navigation

ToggleGroup.Root props (multiple)

PropTypeDefaultDescription
type'multiple'requiredAny number of toggles active
valuestring[]Controlled selected values
defaultValuestring[][]Initial selected values (uncontrolled)
onChange(value: string[]) => voidCalled when the selection changes
disabledbooleanfalseDisable the whole group
orientation'horizontal' | 'vertical''horizontal'Layout + arrow-key axis
loopbooleantrueWrap arrow-key focus from last → first
rovingFocusbooleantrueManage focus as a single tab stop with arrow-key navigation

Data attributes

AttributeElementValues
data-stateToggle"on" / "off"
data-disabledToggle, ToggleGroup.RootPresent when disabled
data-orientationToggleGroup.Root"horizontal" / "vertical"
data-hover / data-active / data-focus-visibleToggleStandard interactive states

Accessibility

  • Each Toggle renders as <button> with aria-pressed reflecting the current state.
  • ToggleGroup.Root sets role="group" and aria-orientation.
  • Inside a group with rovingFocus, the group is a single tab stop: only the active item is tabbable (tabindex={0}), the rest are tabindex={-1}, and arrow keys move focus. Disabled toggles are skipped.

Keyboard Interactions

KeyDescription
Space / EnterToggles the focused button on/off.
ArrowRight / ArrowDownMove focus to the next toggle in the group (axis depends on orientation).
ArrowLeft / ArrowUpMove focus to the previous toggle in the group.
HomeFocus the first toggle in the group.
EndFocus the last toggle in the group.
TabMoves focus to the group (single tab stop), then out of it.
Last updated on

MIT License © 2026 wire-ui

Toggle – Wire UI