Switch
Switches are UI elements that let users choose between two states—most commonly on/off.
Switch API
Import
import { Switch } from '@mui/base/Switch';
// or
import { Switch } from '@mui/base';
Props of the native component are also available.
Callback fired when the state is changed.
Type:func
function(event: React.ChangeEvent) => void
event
The event source of the callback. You can pull out the new value by accessingevent.target.value
(string). You can pull out the new checked state by accessingevent.target.checked
(boolean).
The props used for each slot inside the Switch.
Type:{ input?: func
| object, root?: func
| object, thumb?: func
| object, track?: func
| object }
Default:{}
The components used for each slot inside the Switch. Either a string to use a HTML element or a component.
See Slots API below for more details.
Type:{ input?: elementType, root?: elementType, thumb?: elementType, track?: elementType
| null }
Default:{}
ref
is forwarded to the root element.To learn how to customize the slot, check out the Overriding component structure guide.
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.