Toggle SwitchLoading saved progress…

Toggle Switch

A toggle switch is a two-state control that exposes one boolean as both visible and accessible state. Build it as a React component whose track, knob, status text, and aria-checked value all derive from the same state value.

Signature

Implement the default App component in App.tsx. It receives no props and owns an on boolean with useState(false).

Examples

  • At first load, the grey track has its knob on the left, the status reads Off, and the button exposes aria-checked="false".
  • Clicking the switch changes the track to green, moves the knob right, changes the status to On, and exposes aria-checked="true".
  • Clicking again returns every visible and accessible state to off.

Notes

  • Use one source of truth. Derive the class, ARIA value, and status from on; do not store them separately.
  • Use a native button. Keep role="switch" on the <button> so click, Space, Enter, and focus behavior are built in.
  • Give it a name. Associate the visible Notifications label with aria-labelledby.
  • Leave motion to CSS. The on class changes the track color and knob transform.
WE’RE LISTENING

Help make UIReady better

Found a bug or have an idea? Tell us about it.

Up to 3 files · 5 MiB each · JPG, PNG, WebP, MP4, WebM, MP3, M4A or WAV