shadcn.io is not affiliated with official shadcn/ui
Switch examples · Standard
Disabled Switch for React
A disabled switch that shows its state but can't be toggled.
A Switch that can't be changed: the feature isn't available yet, the plan doesn't include it, or a prerequisite is missing. It stays visible at half opacity so people still see the setting, and it is skipped by the keyboard.
Preview
Installation
FAQ
How is this switch disabled?
The demo disables the Switch. That sets data-disabled, which fades it to half opacity and sets cursor-not-allowed, and the switch leaves the tab order.
The prop is disabled.
How do I tell people why it is disabled?
Say it in text near the switch, such as a FieldDescription under its label. A disabled control can't take focus, so a tooltip on the switch itself won't open from the keyboard.
How do I control this switch in React?
Nothing in this file sets the on state, so the switch starts off and keeps its own state. To control it, keep the on or off state in your own state and pass it back. To start it on, use the default prop.
The prop is defaultChecked.
Pass checked; onCheckedChange receives the new boolean.
What do screen readers call this switch?
It has no visible label, so the demo passes aria-label (Bluetooth). Change it to the setting the switch controls, or use a visible FieldLabel instead.
Related
- Default SwitchA switch in its default off state, with
- Checked SwitchA switch that starts on and keeps its own
- Small SwitchA small switch for dense layouts such as
- Square SwitchA switch with square corners on its track
- Feature Card SwitchA bordered card with an icon, a label, a
- Switch in ItemAn outlined item with a title, a