Skip to Content

Switch

A brandless toggle switch wrapping <input type="checkbox" role="switch">. The role="switch" attribute overrides the default checkbox ARIA role so screen readers announce the control as a toggle (on/off) rather than a checkbox (checked/unchecked).

Usage

import { Switch } from '@froglet/ui' function Example() { const [enabled, setEnabled] = useState(false) return <Switch checked={enabled} onChange={() => setEnabled(!enabled)} /> } // Themed <Switch className="switch--froglet" checked={enabled} onChange={() => setEnabled(!enabled)} />

Props

PropTypeDefaultDescription
checkedbooleanControlled checked state.
onChange(e) => void() => {}Change handler.
disabledbooleanfalseDisables the switch.
rolestring"switch"ARIA role. Override to "checkbox" to revert screen reader semantics.
classNamestringAdditional CSS classes. Use to apply a token block.
refReact.Ref<HTMLInputElement>Forwarded to the underlying <input>.

CSS Custom Properties

TokenDefaultDescription
--switch-width2.5remTrack width.
--switch-height1.25remTrack height.
--switch-border-radius9999pxTrack corner rounding (pill).
--switch-background-colorGrayTextTrack color (unchecked).
--switch-background-color-hover(same as base)Track color (unchecked hover).
--switch-background-color-checkedcurrentColorTrack color (checked).
--switch-background-color-disabledGrayTextTrack color (disabled).
--switch-thumb-size1remThumb diameter.
--switch-thumb-colorCanvasThumb fill.
--switch-thumb-color-disabledCanvasThumb fill (disabled).
--switch-thumb-offset0.125remGap between thumb and track edge.
--switch-outline-width-focus2pxFocus ring width.
--switch-outline-color-focuscurrentColorFocus ring color.
--switch-outline-offset-focus2pxFocus ring offset.

Accessibility

  • role="switch" marks the control as an on/off toggle. Screen readers announce state as “on” or “off”.
  • To revert to standard checkbox semantics, pass role="checkbox".
  • Focus ring uses :focus-visible only.
  • A visible label (<label> or aria-label) is required for screen reader users.
Last updated on