Swap

Animated toggle between two icon/content states with rotate or flip transition

Category: inputs · WCAG 2.2-AA · toggle, icon, animate, switch, flip, rotate

Variants

States

Props

PropTypeDefaultDescription
labelstring—Alias of `ariaLabel` — the same invisible accessible name under the other spelling. Neither is deprecated.
ariaLabelstring—Invisible accessible name. The catalog convention; `aria-label` is accepted as an alias for the DOM spelling.
onReact.ReactNode—Content shown in the active (on) state.
offReact.ReactNode—Content shown in the inactive (off) state.
checkedbooleanfalseWhether the control is checked (controlled).
onValueChange(checked: boolean) => void—Called with the new checked state when the swap is toggled.
mode'rotate' | 'flip'rotateTransition between states ('rotate' | 'flip').
aria-labelstring—Accessible label used when no visible label is present.
classNamestring—Additional CSS class names merged onto the root element.

Design tokens

When to use

When not to use

How to build an accessible Swap in React →

Examples

Theme toggle (rotate)

Sun/moon icon that rotates between two states

<Swap on={<SunIcon />} off={<MoonIcon />} mode="rotate" aria-label="Toggle theme" />

Flip mode

Heart icon that flips to filled on activation

<Swap on={<HeartFilledIcon />} off={<HeartIcon />} mode="flip" aria-label="Favorite" />

Related components

← Back to docs