Switch

Switch is a binary toggle control — use it for settings that take immediate effect without a confirmation step.

tsx
import { Switch } from '@/components/ui/wideset/switch/Switch';

<Switch defaultChecked>
  <Switch.Label>Email notifications</Switch.Label>
</Switch>

Installation

pnpm dlx wideset add switch

Copies the component and any Wideset components it uses into your project.

Examples

Sizes

Large is the default and suits settings pages and forms. Small is for dense places such as table rows, toolbars and side panels. Keep one size within a list of switches.

tsx
import { Switch } from '@/components/ui/wideset/switch/Switch';

export default function SwitchSizes() {
  return (
    <div className="gap-ws-12 flex flex-col items-start">
      {(['lg', 'sm'] as const).map((size) => (
        <Switch key={size} size={size} label="Email notifications" defaultChecked />
      ))}
    </div>
  );
}

Label position

The label sits on the right by default, which reads best in a form. Put it on the left in a settings list, where the labels line up on one edge and the switches on the other. The whole label is part of the click target either way.

tsx
import { Switch } from '@/components/ui/wideset/switch/Switch';

export default function SwitchLabelPosition() {
  return (
    <div className="gap-ws-11 flex flex-wrap items-center justify-center">
      <Switch labelPosition="right" label="Email notifications" defaultChecked />
      <Switch labelPosition="left" label="Email notifications" defaultChecked />
    </div>
  );
}

States

Hover, press and focus are live. A switch takes effect the moment it flips, with no save button; Space or Enter toggles it from the keyboard. A disabled switch leaves the tab order, so say near it why it is locked.

tsx
import { Switch } from '@/components/ui/wideset/switch/Switch';

export default function SwitchStates() {
  return (
    <div className="gap-x-ws-11 gap-y-ws-7 grid grid-cols-[4rem_repeat(2,auto)] items-center">
      <span className="typography-caption-md text-ws-static-subtle">Default</span>
      <Switch label="Off" />
      <Switch label="On" defaultChecked />
      <span className="typography-caption-md text-ws-static-subtle">Disabled</span>
      <Switch label="Off" disabled />
      <Switch label="On" defaultChecked disabled />
    </div>
  );
}

API reference

Switch

NameDescriptionDefault
children

Composed label and description (one `Switch.Description`). Use instead of the shorthand label.

ReactNode
—
defaultMotion

Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`.

boolean
true
label

Shorthand label, mutually exclusive with composed children.

string
—
labelPosition

Position of label in accordance to the Switch

'left''right'
'right'
size
'sm''lg'
'lg'
wrapperClassName

Classes for the row that holds the switch and its label.

string
—

Switch.Label

No props of its ownIt takes its content as children.
Every other prop of Radix Label.Root is passed through to it. See Radix Label.Root.

Accessibility

  • Space or Enter toggles it; it is announced as a switch, on or off.
  • Without a visible label, pass aria-label.
  • With label, the whole row is the click target.
PartRendersDescription
Switch—A binary setting that takes effect immediately.
Switch.LabelRadix Label.RootThe text label associated with `Switch`.
tsx
import { Switch } from '@/components/ui/wideset/switch/Switch';

<Switch defaultChecked>
  <Switch.Label>Email notifications</Switch.Label>
</Switch>

Appearance

Size
Label position

State

Checked
Disabled