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.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.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>
);
}
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"
/>
);
}
SwitchProps.| Prop | Type | Default | Description |
|---|---|---|---|
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.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.checked is the single source of truth. Clicking the switch does nothing; wire activation on the parent.--uit-color-background-inset and the on track uses --uit-color-persistent-action; the thumb ring and fill use --uit-color-control-active.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.usePrefersReducedMotion with animated when you want the transition suppressed for users who ask for less motion.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 forwards to the root div, which is all you need for measuring or anchoring something to the switch.role="switch" with aria-checked reflecting checked, so assistive technology announces the state.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.aria-label when nothing adjacent names the setting.ListItem with showSwitch instead.ListItem with showSwitch for any setting the user can change.animated with usePrefersReducedMotion in motion-sensitive surfaces.ListItem.Switch plus a focusable wrapper; the result announces two widgets.