Switch
Props
API reference for Switch. For usage examples, see the React tab.
| Name | Type | Default |
|---|---|---|
| children* (required) | ReactNode | — |
The label of the switch. | ||
| defaultSelected | boolean | — |
Whether the element should be selected (uncontrolled). | ||
| description | string | — |
Helper text for the switch. | ||
| inputRef | RefObject<HTMLInputElement> | — |
React 19 only | ||
| isDisabled | boolean | — |
Whether the input is disabled. | ||
| isInvalid | boolean | — |
Whether the input value is invalid. | ||
| isReadOnly | boolean | — |
Whether the input can be selected but not changed by the user. | ||
| isRequired | boolean | — |
Whether user input is required on the input before form submission. | ||
| isSelected | boolean | — |
Whether the element should be selected (controlled). | ||
| labelPosition | "left" | "right" | "top" | null | — |
| Name | Type | Default |
|---|---|---|
| aria-controls | string | — |
Identifies the element (or elements) whose contents or presence are controlled by the current element. | ||
| aria-describedby | string | — |
Identifies the element (or elements) that describes the object. | ||
| aria-details | string | — |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
| aria-errormessage | string | — |
Identifies the element that provides an error message for the object. | ||
| aria-label | string | — |
Defines a string value that labels the current element. | ||
| aria-labelledby | string | — |
Identifies the element (or elements) that labels the current element. | ||
| id | string | — |
The element's unique identifier. See MDN (opens in new tab). | ||
| Name | Type | Default |
|---|---|---|
| autoFocus | boolean | — |
Whether the element should receive focus on render. | ||
| dir | string | — |
| excludeFromTabOrder | boolean | — |
Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. | ||
| hidden | boolean | — |
| inert | boolean | — |
| lang | string | — |
| ref | Ref<HTMLDivElement> | — |
React 19 only | ||
| render | DOMRenderFunction<"div", SwitchFieldRenderProps> | — |
Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
| ||
| slot | string | null | — |
A slot name for the component. Slots allow the component to receive props from a parent component. An explicit | ||
| suppressHydrationWarning | boolean | — |
A React-only flag that suppresses the warning React normally logs when an element's server-rendered content doesn't match the client render during hydration. See React docs (opens in new tab). | ||
| translate | "no" | "yes" | — |
| Name | Type | Default |
|---|---|---|
| onAnimationEnd | AnimationEventHandler<HTMLDivElement> | — |
| onAnimationEndCapture | AnimationEventHandler<HTMLDivElement> | — |
| onAnimationIteration | AnimationEventHandler<HTMLDivElement> | — |
| onAnimationIterationCapture | AnimationEventHandler<HTMLDivElement> | — |
| onAnimationStart | AnimationEventHandler<HTMLDivElement> | — |
| onAnimationStartCapture | AnimationEventHandler<HTMLDivElement> | — |
| onAuxClick | MouseEventHandler<HTMLDivElement> | — |
| onAuxClickCapture | MouseEventHandler<HTMLDivElement> | — |
| onBlur | ((e: FocusEvent<Element, Element>) => void) | — |
Handler that is called when the element loses focus. | ||
| onChange | ((isSelected: boolean) => void) | — |
Handler that is called when the element's selection state changes. | ||
| onClick | ((e: MouseEvent<FocusableElement, MouseEvent>) => void) | — |
Not recommended – use `onPress` instead. | ||
| onClickCapture | MouseEventHandler<HTMLDivElement> | — |
| onContextMenu | MouseEventHandler<HTMLDivElement> | — |
| onContextMenuCapture | MouseEventHandler<HTMLDivElement> | — |
| onDoubleClick | MouseEventHandler<HTMLDivElement> | — |
| onDoubleClickCapture | MouseEventHandler<HTMLDivElement> | — |
| onFocus | ((e: FocusEvent<Element, Element>) => void) | — |
Handler that is called when the element receives focus. | ||
| onFocusChange | ((isFocused: boolean) => void) | — |
Handler that is called when the element's focus status changes. | ||
| onGotPointerCapture | PointerEventHandler<HTMLDivElement> | — |
| onGotPointerCaptureCapture | PointerEventHandler<HTMLDivElement> | — |
| onKeyDown | ((e: KeyboardEvent) => void) | — |
Handler that is called when a key is pressed. | ||
| onKeyUp | ((e: KeyboardEvent) => void) | — |
Handler that is called when a key is released. | ||
| onLostPointerCapture | PointerEventHandler<HTMLDivElement> | — |
| onLostPointerCaptureCapture | PointerEventHandler<HTMLDivElement> | — |
| onMouseDown | MouseEventHandler<HTMLDivElement> | — |
| onMouseDownCapture | MouseEventHandler<HTMLDivElement> | — |
| onMouseEnter | MouseEventHandler<HTMLDivElement> | — |
| onMouseLeave | MouseEventHandler<HTMLDivElement> | — |
| onMouseMove | MouseEventHandler<HTMLDivElement> | — |
| onMouseMoveCapture | MouseEventHandler<HTMLDivElement> | — |
| onMouseOut | MouseEventHandler<HTMLDivElement> | — |
| onMouseOutCapture | MouseEventHandler<HTMLDivElement> | — |
| onMouseOver | MouseEventHandler<HTMLDivElement> | — |
| onMouseOverCapture | MouseEventHandler<HTMLDivElement> | — |
| onMouseUp | MouseEventHandler<HTMLDivElement> | — |
| onMouseUpCapture | MouseEventHandler<HTMLDivElement> | — |
| onPointerCancel | PointerEventHandler<HTMLDivElement> | — |
| onPointerCancelCapture | PointerEventHandler<HTMLDivElement> | — |
| onPointerDown | PointerEventHandler<HTMLDivElement> | — |
| onPointerDownCapture | PointerEventHandler<HTMLDivElement> | — |
| onPointerEnter | PointerEventHandler<HTMLDivElement> | — |
| onPointerLeave | PointerEventHandler<HTMLDivElement> | — |
| onPointerMove | PointerEventHandler<HTMLDivElement> | — |
| onPointerMoveCapture | PointerEventHandler<HTMLDivElement> | — |
| onPointerOut | PointerEventHandler<HTMLDivElement> | — |
| onPointerOutCapture | PointerEventHandler<HTMLDivElement> | — |
| onPointerOver | PointerEventHandler<HTMLDivElement> | — |
| onPointerOverCapture | PointerEventHandler<HTMLDivElement> | — |
| onPointerUp | PointerEventHandler<HTMLDivElement> | — |
| onPointerUpCapture | PointerEventHandler<HTMLDivElement> | — |
| onPress | ((e: PressEvent) => void) | — |
Handler that is called when the press is released over the target. | ||
| onPressChange | ((isPressed: boolean) => void) | — |
Handler that is called when the press state changes. | ||
| onPressEnd | ((e: PressEvent) => void) | — |
Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. | ||
| onPressStart | ((e: PressEvent) => void) | — |
Handler that is called when a press interaction starts. | ||
| onPressUp | ((e: PressEvent) => void) | — |
Handler that is called when a press is released over the target, regardless of whether it started on the target or not. | ||
| onScroll | UIEventHandler<HTMLDivElement> | — |
| onScrollCapture | UIEventHandler<HTMLDivElement> | — |
| onTouchCancel | TouchEventHandler<HTMLDivElement> | — |
| onTouchCancelCapture | TouchEventHandler<HTMLDivElement> | — |
| onTouchEnd | TouchEventHandler<HTMLDivElement> | — |
| onTouchEndCapture | TouchEventHandler<HTMLDivElement> | — |
| onTouchMove | TouchEventHandler<HTMLDivElement> | — |
| onTouchMoveCapture | TouchEventHandler<HTMLDivElement> | — |
| onTouchStart | TouchEventHandler<HTMLDivElement> | — |
| onTouchStartCapture | TouchEventHandler<HTMLDivElement> | — |
| onTransitionCancel | TransitionEventHandler<HTMLDivElement> | — |
| onTransitionCancelCapture | TransitionEventHandler<HTMLDivElement> | — |
| onTransitionEnd | TransitionEventHandler<HTMLDivElement> | — |
| onTransitionEndCapture | TransitionEventHandler<HTMLDivElement> | — |
| onTransitionRun | TransitionEventHandler<HTMLDivElement> | — |
| onTransitionRunCapture | TransitionEventHandler<HTMLDivElement> | — |
| onTransitionStart | TransitionEventHandler<HTMLDivElement> | — |
| onTransitionStartCapture | TransitionEventHandler<HTMLDivElement> | — |
| onWheel | WheelEventHandler<HTMLDivElement> | — |
| onWheelCapture | WheelEventHandler<HTMLDivElement> | — |
| Name | Type | Default |
|---|---|---|
| errorMessage | string | ((validation: ValidationResult) => string) | — |
Custom error message to display when the switch is invalid. | ||
| form | string | — |
The | ||
| name | string | — |
The name of the input element, used when submitting an HTML form. See MDN (opens in new tab). | ||
| validate | ((value: boolean) => true | ValidationError | null) | — |
A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if | ||
| validationBehavior | "aria" | "native" | 'native' |
Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA. | ||
| value | string | — |
The value of the input element, used when submitting an HTML form. See MDN (opens in new tab). | ||
| Name | Type | Default |
|---|---|---|
| className | ClassNameOrFunction<SwitchFieldRenderProps> | 'react-aria-SwitchField' |
The CSS className (opens in new tab) for the element. A function may be provided to compute the class based on component state. | ||
| style | StyleOrFunction<SwitchFieldRenderProps> | — |
The inline style (opens in new tab) for the element. A function may be provided to compute the style based on component state. | ||