Skip to content

Switch

Turn a setting on or off, with an immediate effect.

Installation

Terminal
pnpm dlx shadcn@latest add https://react-toolbox.io/r/switch.json

New here? Set up your project first. Styles, fonts, and required components are included.

Usage

Use a short label that names the setting, such as “Do not disturb,” and apply changes immediately.

State and callbacks

Use checked/onChange for controlled state, or defaultChecked for native form state and reset. onChange receives the next boolean, then the input click event.

API reference

Key props and defaults. Full types and inline documentation are included with the source in material/switch.

Switch

Property Type Default
label React.ReactNode —
onChange (checked: boolean, event: React.MouseEvent<HTMLInputElement>) => void —

Material guidelines

  • Use a switch for a single setting with an immediate on/off effect. Describe the setting itself in its label.
  • Use checkboxes for independent selections in a set and radios for mutually exclusive choices.

Material Design 1: Selection controls