structyl

Switch API

View component

The full prop reference for the Switch component. A control that allows the user to toggle between checked and not checked.

Import

tsx
import { Switch } from '@structyl/styled';

Props

Switch

Accessible switch/toggle component with controlled and uncontrolled modes, styled with Tailwind variants for size and color.

PropTypeDefault
checked#boolean

Controlled checked state of the switch

defaultChecked#boolean

Initial checked state (uncontrolled mode)

onCheckedChange#(checked: boolean) => void

Callback fired when the checked state changes

disabled#boolean

When true, the switch is disabled and cannot be toggled

required#boolean

When true, indicates the switch is required in a form

name#string

Form name attribute; creates a hidden input for form submission

value#string

Form value when the switch is checked

'on'
asChild#boolean

Render as child (Slot pattern); merges props onto the first child element

size#'sm' | 'md' | 'lg'

Switch size variant (styled layer)

'md'
color#'primary' | 'secondary' | 'error' | 'warning' | 'info' | 'success'

Switch color variant when checked (styled layer)

'primary'
className#string

CSS class names merged with variant styles

onClick#(event: React.MouseEvent<HTMLButtonElement>) => void

Native click handler (merged with toggle logic)

ref#React.Ref<HTMLButtonElement>

Forward ref to the underlying button element

Keyboard interactions

Adheres to the WAI-ARIA design pattern .

KeyDescription
Space / EnterToggles the switch.

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library