Skip to content
shadcn.io

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.

Framework
UI library

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

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

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.

How do I add a visible label to this switch?

Put the Switch in a horizontal Field next to a FieldLabel. Clicking the label toggles the switch, and screen readers read the label with it. Give the Switch an id and set the same value as htmlFor on the FieldLabel.

Does this switch submit with a form?

Give it a name. When on, it submits its value, which defaults to on. When off, it submits nothing. With Base UI, uncheckedValue sets what it submits when off.