Toggle

Switches something on or off. Two looks: switch and checkbox. Both are a standard toggle underneath.

Usage

Web (React)

const [wifi, setWifi] = useState(true);
const [agree, setAgree] = useState(false);
return (
  <>
    <DotwearToggle checked={wifi} onChange={setWifi}>
      Wi-Fi
    </DotwearToggle>

    <DotwearToggle variant="checkbox" checked={agree} onChange={setAgree}>
      I agree to the terms
    </DotwearToggle>
  </>
);

iOS (SwiftUI)

Toggle("Wi-Fi", isOn: $wifi)
    .toggleStyle(.dotwear)               // switch

Toggle("I agree to the terms", isOn: $agree)
    .toggleStyle(.dotwear(.checkbox))

React Native

const [wifi, setWifi] = useState(true);
const [agree, setAgree] = useState(false);
return (
  <>
    <DotwearToggle value={wifi} onValueChange={setWifi}>
      Wi-Fi
    </DotwearToggle>

    <DotwearToggle variant="checkbox" value={agree} onValueChange={setAgree}>
      I agree to the terms
    </DotwearToggle>
  </>
);

Flutter

DotwearToggle(
  value: wifi,
  onChanged: (v) => setState(() => wifi = v),
  child: const Text('Wi-Fi'),
),

DotwearToggle(
  variant: DotwearToggleVariant.checkbox,
  value: agree,
  onChanged: (v) => setState(() => agree = v),
  child: const Text('I agree to the terms'),
),

Variants

VariantUse for
switchSettings that apply immediately (default)
checkboxForms that are submitted together, or multiple selection

States

StateAppearance
offBackground bg, one-dot shadow
onBackground primary (switch knob on the right / check mark)
pressedShadow removed, body shifts down by one dot
focusedOne-dot focus ring
disabledDisabled colors

React API

PropDescription
variant="switch""switch" (default, role="switch") or "checkbox"
checked / onChange(checked, event)onChange receives the new boolean first, so onChange={setWifi} works
childrenThe label. Clicking it toggles too. Without a visible label, pass aria-label
…input propsAny checkbox <input> attribute (name, value, disabled, defaultChecked, …)

SwiftUI API

APIDescription
.toggleStyle(.dotwear)Switch
.toggleStyle(.dotwear(.checkbox))Checkbox

React Native API

PropDescription
variant="switch""switch" (default, accessibilityRole="switch") or "checkbox"
value / onValueChange(value)Same as the standard Switch, so onValueChange={setWifi} works
childrenThe label. Tapping it toggles too. Without a visible label, pass accessibilityLabel
…Pressable propsdisabled, accessibilityLabel, style, …

Flutter API

ParameterDescription
value / onChangedSame as the standard Switch. onChanged: null disables it
variant: DotwearToggleVariant.switch_.switch_ (default) or .checkbox
childThe label. Tapping it toggles too. Without a visible label, pass semanticLabel

Accessibility

  • Web: a standard checkbox <input> (role="switch" for the switch) wrapped in a <label>, so Space toggles it and clicking the label works.
  • iOS: VoiceOver announces it exactly like a standard Toggle ("Switch, on"), for both looks.
  • React Native: a Pressable with accessibilityRole="switch" or "checkbox" and accessibilityState.checked, so VoiceOver and TalkBack announce the role and state. The label and control are one element.
  • Flutter: reports toggled (switch) or checked (checkbox) like the standard Switch and Checkbox, and Space or Enter toggles it.