Switch

Updated: Sep 24, 2026
Switch draws the on/off state of a boolean setting: a pill track with a thumb that slides between the off and on positions. It is a visual building block, not an input. It has no change callback, takes no focus, and never modifies its own state — the parent that owns the setting passes checked down and updates it.
For an ordinary settings row, do not compose Switch yourself. Use ListItem with showSwitch, which gives you one large focus target, the row label, and a single onCheckedChange callback. ListItem also owns the switch role and state, so the row is announced as a single widget rather than a widget containing another widget.

Usage

The recommended interactive form is a list row:
import { useState } from 'react';
import { ListItem, VerticalList } from '@wearables-ui-toolkit/mrbd';

export function ConnectivitySettings() {
  const [wifiEnabled, setWifiEnabled] = useState(true);

  return (
    <VerticalList>
      <ListItem
        title="Wi-Fi"
        subtitle={wifiEnabled ? 'Connected' : 'Off'}
        showSwitch
        checked={wifiEnabled}
        onCheckedChange={setWifiEnabled}
      />
    </VerticalList>
  );
}
Use Switch directly only when you are presenting state that some other, clearly labelled control owns — for example a read-only summary:
import { Switch, usePrefersReducedMotion } from '@wearables-ui-toolkit/mrbd';

export function RecordingIndicator({ isRecording }: { isRecording: boolean }) {
  const prefersReducedMotion = usePrefersReducedMotion();

  return (
    <Switch
      checked={isRecording}
      animated={!prefersReducedMotion}
      aria-label="Recording"
    />
  );
}

Props

The full prop type is SwitchProps.
PropTypeDefaultDescription
checked
boolean
false
Whether the switch draws the on position. Fully controlled; the component never changes it.
animated
boolean
true
Whether a change to checked animates. The very first render always snaps.
SwitchProps also accepts the standard div attribute surface — className, style, aria-label, title, data-* (including data-uit-*), and DOM event handlers — which is spread onto the root element. There is no onChange prop (it is removed from the accepted attributes) and no disabled prop.
The component supplies its own role, aria-checked, aria-disabled, aria-hidden, tabIndex, onClick, and onKeyDown after the rest props, so none of those can be overridden: an onClick or onKeyDown you pass to Switch is never attached, and an aria-hidden or aria-disabled you pass is dropped. Other handlers, such as onFocus and onPointerEnter, do reach the root element.

Behavior

  • Controlled only.checked is the single source of truth. Clicking the switch does nothing; wire activation on the parent.
  • Rendering. The switch draws an inline SVG: a pill track, a thumb outline ring, and a thumb fill. The off track uses --uit-color-background-inset and the on track uses --uit-color-persistent-action; the thumb ring and fill use --uit-color-control-active.
  • Motion. On a change to checked the thumb translates between the off and on positions, the track colour transitions between the two states, and the thumb fill fades in as it turns on. All three use the shared container state-change duration and easing. Setting animated to false snaps instead.
  • Mount. The initial paint never animates, so a row that mounts already on does not visibly toggle.
  • Reduced motion. The component does not read the system reduced-motion setting on its own. Combine usePrefersReducedMotion with animated when you want the transition suppressed for users who ask for less motion.
  • Sizing. The switch has a fixed intrinsic width and height written as inline styles on an inline-flex root, and it does not shrink in a flex row. Your style object is merged after those, so a width or height there would win. Let the parent lay the switch out instead to preserve its component-owned size.
  • Ref. The ref forwards to the root div, which is all you need for measuring or anchoring something to the switch.

Accessibility

  • The component reports role="switch" with aria-checked reflecting checked, so assistive technology announces the state.
  • It is not focusable and not operable: there is no tab stop, no key handling, and the root keeps the default cursor rather than a pointer affordance. The accessible action belongs to the parent.
  • It is never hidden from assistive technology, and aria-hidden cannot be turned on from the outside. That is why nesting it inside another control is a problem rather than a styling choice.
  • Give it an aria-label when nothing adjacent names the setting.
  • Do not place it inside an element that already reports switch semantics; that produces a duplicate nested widget. Use ListItem with showSwitch instead.
  • Use ListItem with showSwitch for any setting the user can change.
  • Keep one state value and one update path per switch.
  • Represent an independent binary setting that takes effect immediately.
  • Pair animated with usePrefersReducedMotion in motion-sensitive surfaces.

Avoid

  • Avoid using a switch for a one-time command; use Button or a plain ListItem.
  • Avoid attaching your own click or key handler to the switch element — it will be dropped, and the switch will look interactive without being operable.
  • Avoid building your own labelled toggle row out of Switch plus a focusable wrapper; the result announces two widgets.
  • Avoid binding two separately labelled switches to the same boolean.
  • Use the component-owned track and thumb. Internal DOM structure and generated class names are not supported customization surfaces.