Switch
Switches are UI elements that let users choose between two states—most commonly on/off.
useSwitch API
Import
import { useSwitch } from '@mui/base/useSwitch';
// or
import { useSwitch } from '@mui/base';Learn about the difference by reading this guide on minimizing bundle size.
| Name | Type | Description |
|---|---|---|
| checked | boolean | If |
| defaultChecked | boolean | The default checked state. Use when the component is not controlled. |
| disabled | boolean | If |
| onBlur | React.FocusEventHandler | |
| onChange | React.ChangeEventHandler<HTMLInputElement> | Callback fired when the state is changed. |
| onFocus | React.FocusEventHandler | |
| onFocusVisible | React.FocusEventHandler | |
| readOnly | boolean | If |
| required | boolean | If |
| Name | Type | Description |
|---|---|---|
| checked | boolean | If |
| disabled | boolean | If |
| focusVisible | boolean | If |
| getInputProps | (externalProps?: React.HTMLAttributes<HTMLInputElement>) => UseSwitchInputSlotProps | Resolver for the input slot's props. |
| inputRef | React.RefCallback<HTMLInputElement> | null | Ref to the input slot's DOM node. |
| readOnly | boolean | If |