SwitchA control that allows the user to toggle between checked and not checked.
The Switch component accepts the following props:
Add labels to provide context for your switches.
Use the Switch component in a controlled manner to manage its state externally.
The Switch component follows WAI-ARIA guidelines for toggle buttons:
The Switch component provides a toggleable control with support for controlled and disabled states.
Install the component from your command line.
npm install @raystack/apsara
import { Switch } from '@raystack/apsara/v1' <Switch checked={true} />
checked
: The controlled checked state of the switch (boolean)defaultChecked
: The default checked state when uncontrolled (boolean)onCheckedChange
: Event handler called when the checked state changes (function)disabled
: When true, prevents the user from interacting with the switch (boolean)required
: When true, indicates that the user must check the switch (boolean)id
: A unique identifier for the switch (string)
loading...
loading...
loading...
- Uses proper ARIA attributes (
aria-checked
,aria-required
,aria-label
) - Supports keyboard navigation (Space and Enter to toggle)
- Includes proper labeling and description support
- Changes cursor to 'not-allowed' when disabled
- Associates labels with the switch using htmlFor