Skip to content

Switch

A wrapper around React Aria’s Switch component. Provides keyboard, pointer, and touch interaction with proper ARIA role and state management.

Terminal window
npx @a2ra/cli add switch
{
"type": "Switch",
"props": {
"label": "Dark mode",
"name": "darkMode",
"value": "on",
"defaultSelected": false
}
}
PropTypeDescription
labelstringVisible label text
isSelectedbooleanControlled on/off state
defaultSelectedtrue
false default
Uncontrolled default
isDisabledtrue
false default
Disables the switch
isReadOnlytrue
false default
Prevents toggling
isRequiredtrue
false default
Marks as required
isInvalidtrue
false default
Shows error styling
validationBehavioraria default
native
Validation strategy
namestringForm field name
valuestringValue submitted when selected
descriptionstringHelper text shown below the label
errorMessagestringError text when isInvalid is true
  • Switch uses role="switch" so screen readers announce it as a toggle, not a checkbox.
  • value is the string submitted with the form when the switch is on (like a checkbox value).