Switch
Capture boolean input from user
Import
Source
Docs
Package
Usage
Controlled
Inner Labels
Icon labels
Thumb icon
With tooltip
Set refProp="rootRef"
on Tooltip and other similar components to make them work with Switch
:
Pointer cursor
By default, switch input and label have cursor: default
(same as native input[type="checkbox"]
).
To change cursor to pointer, set cursorType
on theme:
Add props to the root element
All props passed to the component are forwarded to the input element. If you need to add props to the root element, use wrapperProps
. In the following example:
data-testid="wrapper"
is added to the root elementdata-testid="input"
is added to the input element
Switch.Group
This is anonymous
Controlled Switch.Group
Styles API
Switch
supports Styles API, you can add styles to any inner element of the component withclassNames
prop. Follow Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Get input ref
Accessibility
Switch
is a regular input[type="checkbox"]
. Set aria-label
if the Switch
is used without label
prop: