Skip to content

Switch

Binary toggle control. The thumb slides along a spring curve, with a slight stretch on press for a tactile feel.

Basic Usage

tsx
import { Switch } from '@airo-ui/react'
import { useState } from 'react'

function Demo() {
  const [on, setOn] = useState(true)

  return (
    <div style={{ display: 'flex', gap: 16 }}>
      <Switch checked={on} onChange={setOn} />
      <Switch />
    </div>
  )
}

Size

tsx
<Switch checked size="sm" />
<Switch checked size="md" />

Loading / Disabled

tsx
<Switch loading />
<Switch checked disabled />
<Switch disabled />

API

Props

NameTypeDefaultDescription
checkedboolean--Controlled toggle state
defaultCheckedbooleanfalseDefault state (uncontrolled)
disabledbooleanfalseDisabled
loadingbooleanfalseLoading state, shows spinner
size'sm' | 'md''md'Size
onChange(checked: boolean) => void--State change handler

Accessibility

  • Uses native <button role="switch">, aria-checked reflects state
  • Space / Enter keys to toggle
  • Focus ring follows global :focus-visible style

MIT License