structyl

Switch

stable

A control that allows the user to toggle between checked and not checked.

Basic usage

Examples

Controlled toggle

Track the checked state externally to drive other UI.

Status: disabled

Settings list

Use controlled or uncontrolled switches inside dense settings panels.

Release preferences
Realistic app composition
Example

Semantic colors

Switch accepts a color prop to match the semantic context of the toggle.

Features

  • Full keyboard navigation.
  • Can be controlled or uncontrolled.
  • iOS-style spring thumb animation.

Installation

bash
pnpm dlx structyl add switch

API Reference

Switch

A toggle control with role="switch".

PropTypeDefault
checkedboolean

Controlled checked state.

defaultCheckedboolean

Initial checked state when uncontrolled.

onCheckedChange(checked: boolean) => void

Called when the checked state changes.

disabledboolean

Disable the switch.

false
requiredboolean

Mark as required in a form.

false
namestring

Name for form submission.

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

Visual size.

'md'
classNamestring

Additional Tailwind classes, merged with the component defaults.

Keyboard interactions

Adheres to the WAI-ARIA design pattern .

KeyDescription
Space / EnterToggles the switch.
Switch | structyl