shadcn.io is not affiliated with official shadcn/ui
The Switch with small radii instead of a pill, for interfaces with square buttons and inputs, such as editors and developer tools. Only classes change: the behavior, keyboard and states are the Switch's own.
Preview
Installation
FAQ
How are the corners squared off?
The Switch sets rounded-sm for the track and **:data-[slot=switch-thumb]:rounded for the thumb. The thumb is the part with data-slot="switch-thumb", so the selector reaches it on every library.
How do I make every switch square?
Edit the Switch file in your ui folder: replace rounded-full on the track and the thumb there. Then you don't repeat the classes on each switch.
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 (Enable feature). Change it to the setting the switch controls, or use a visible FieldLabel instead.
Related
- Default SwitchA switch in its default off state, with
- Square Switch with TextA square switch with On and Off text that
- Square Switch with LabelA square switch that starts on, with a
- Square Theme Toggle SwitchA compact square switch between a moon
- Simple CheckboxA checkbox with a label for a single
- Button with Text (Outline)A border, no fill