40+ landing page components for ReactBrowse now

Components

Switch

A toggle switch for binary on/off states. Ideal for settings and preferences that take effect immediately.

Installation

npm install @trinkui/react

Import

import { Switch } from "@trinkui/react";

Usage

Basic toggle switch with a label.

<Switch label="Enable notifications" />

<Switch label="Dark mode" defaultChecked />

Sizes

Available in three sizes: sm, md, and lg.

<Switch size="sm" label="Small" />
<Switch size="md" label="Medium" />
<Switch size="lg" label="Large" />

Controlled

Use checked and onChange for controlled behavior.

const [enabled, setEnabled] = useState(false);

<Switch
  checked={enabled}
  onChange={setEnabled}
  label="Airplane mode"
/>

Disabled

Use the disabled prop to prevent interaction.

<Switch label="Locked setting" disabled />
<Switch label="Locked on" disabled defaultChecked />

Props

PropTypeDefaultDescription
checkedboolean-Controlled checked state
defaultCheckedbooleanfalseInitial checked state for uncontrolled usage
onChange(checked: boolean) => void-Callback when the switch is toggled
labelstring-Label text displayed next to the switch
disabledbooleanfalseDisable the switch
size"sm" | "md" | "lg""md"Size of the switch

Accessibility

  • Uses role="switch" for proper semantic meaning.
  • Applies aria-checked to communicate the current state to assistive technologies.
  • Toggleable via keyboard with Space and Enter keys.
  • Label is associated with the switch for click-to-toggle behavior.
  • Visible focus ring when navigating with keyboard.