Switch
A wrapper around React Aria’s Switch component. Provides keyboard, pointer, and touch
interaction with proper ARIA role and state management.
Add via CLI
Section titled “Add via CLI”npx @a2ra/cli add switchWith description
Section titled “With description”Example JSON
Section titled “Example JSON”{ "type": "Switch", "props": { "label": "Dark mode", "name": "darkMode", "value": "on", "defaultSelected": false }}| Prop | Type | Description |
|---|---|---|
label | string | Visible label text |
isSelected | boolean | Controlled on/off state |
defaultSelected | truefalse default | Uncontrolled default |
isDisabled | truefalse default | Disables the switch |
isReadOnly | truefalse default | Prevents toggling |
isRequired | truefalse default | Marks as required |
isInvalid | truefalse default | Shows error styling |
validationBehavior | aria defaultnative | Validation strategy |
name | string | Form field name |
value | string | Value submitted when selected |
description | string | Helper text shown below the label |
errorMessage | string | Error text when isInvalid is true |
Switchusesrole="switch"so screen readers announce it as a toggle, not a checkbox.valueis the string submitted with the form when the switch is on (like a checkboxvalue).