Skip to content
Porcelana

Switch

On/off toggle whose thumb always stays inside the track, as a full-width labelled row.

Example

Example.tsx
import { Switch } from "@porcelana/ui";

export default function Example() {
  return (
    <div style={{ display: "grid", maxWidth: 420 }}>
      <Switch label="Alarm" description="Weekdays at 06:00" defaultChecked />
      <Switch label="Gradual wake light" size="lg" />
      <Switch aria-label="Standalone switch" />
    </div>
  );
}

Import

Import
import { Switch } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app root

Props

Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.

Switch

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
checkedboolean–Controlled checked state. Use with onCheckedChange.
defaultCheckedboolean–Initial checked state when uncontrolled.
descriptionReactNode–Secondary text under the label; becomes the accessible description.
disabledboolean–Prevents interaction and dims the control.
idstring–Element id. Generated automatically when omitted.
labelReactNode–Visible label rendered as a full-width row; tapping the row toggles.
onCheckedChange((checked: boolean) => void)–Called with the new checked state.
requiredboolean–Marks the control as required in forms.
size"md" | "lg"mdmd is 64 × 36px, lg is 96 × 48px.
type"button" | "submit" | "reset"–Button type (defaults to "button").

Accessibility

  • role="switch" with aria-checked; Space and Enter toggle.
  • description becomes the switch's accessible description.

Mobile

  • With label, the whole row toggles, so the target is far larger than the switch.
  • Two sizes: 64 × 36px and 96 × 48px.