Todae

Todae

Switch

On or off. The indicator is a track and a thumb. There is no check glyph. Children are the visible label.

On this page

The input is type="checkbox" with role="switch". Controlled and uncontrolled follow the same rule as Checkbox.

import { Description, Field, Switch } from '@tounsoo/todae';
import { useId, useState } from 'react';

export default function SwitchStates() {
  const hintId = useId();
  const [digest, setDigest] = useState(true);
  return (
    <>
      <Switch.Root defaultChecked>Play a sound on mention</Switch.Root>
      <Field.Group>
        <Switch.Root checked={digest} onCheckedChange={setDigest} aria-describedby={hintId}>
          Send a weekly digest
        </Switch.Root>
        <Description.Root id={hintId}>One email on Monday. No ads.</Description.Root>
      </Field.Group>
      <Switch.Root disabled>Beta channel</Switch.Root>
    </>
  );
}
One email on Monday. No ads.

Density scales the track through space.selection.size. Do not put Switch inside Field.Root.

The thumb slides and the track fades to its on color over selection.motion.duration. When the user prefers reduced motion, the thumb moves without sliding and the track still fades.

Accessible composition

Todae handles: The input is a native <input type="checkbox"> with role="switch", inside a <label> with your children, so the children are its name and it is reported as on or off. Space toggles it. disabled is native and invalid sets aria-invalid; both also come from a surrounding Fieldset. The track is aria-hidden and shows the focus ring while the input is focus-visible. Other props, aria-* and ref included, go to the input; className goes to the label.

You supply: Children that name the setting, such as "Play a sound on mention"; the type requires them. A Description id in aria-describedby when the setting needs explaining. The change itself, applied when it toggles, since a switch reads as taking effect at once.

Watch for: A label that names the state, such as "On", or that changes when toggled: the switch already reports its state. Wrapping it in another <label> or pointing a Label at it. A switch in a form that applies only on submit; use a Checkbox there.

When to use

When: Immediate on/off setting (track + thumb, no check glyph). Children = label.

When not: Form consent / multi-select → Checkbox. Exclusive plans → Radio. Inside Field.Root.

Props

Switch.Root props
NameTypeDescription
children RequiredReact.ReactNode

Visible label. Clicking the text toggles the switch.

checkedboolean

Controlled on state. Defined means controlled.

defaultCheckedboolean

Initial on state when uncontrolled.

onCheckedChange(checked: boolean) => void

Fires after the on state changes.

disabledboolean

Disables the switch.

invalidboolean

Marks the control invalid and sets aria-invalid.

namestring

Native input name.

classNamestring

Optional class on the wrapping label.