Switch
A control component that allows users to toggle between checked and unchecked states. Implements the ARIA switch pattern for proper accessibility support.
Can be controlled or uncontrolled
Full keyboard navigation
Architecture
Reference
-
Switch
The switch component. Coordinates the interaction between the visual indicator and the hidden input element, ensuring proper form submission and accessibility support.
-
Attributes
- aria-labelstring/default: -
Defines an accessible label for the switch when a visible label is not present.
- checkedboolean/default: -
The controlled checked state of the switch. Must be used in conjunction with
onCheckedChange
event handler. - default-checkedboolean/default: false
The initial checked state when the switch is rendered. Use when you do not need to control its checked state.
- disabledboolean/default: false
When
true
, prevents the user from interacting with the switch. - namestring/default: -
The name of the switch when used within a form. Submitted with its owning form as part of a name/value pair.
- requiredboolean/default: false
When
true
, indicates that the switch must be checked before the owning form can be submitted. - tabindexnumber/default: 0
The tab order of the switch within the document's focus flow. Use this to customize the focus sequence when needed.
- valuestring/default: on
The value submitted with the form when the switch is checked. Defaults to "on" if not specified.
-
-
Events
- onCheckedChange
Event handler called when the checked state of the switch changes.
-
-
Keyboard
- Space
Toggles the switch between checked and unchecked states.
- Enter
Toggles the switch between checked and unchecked states.