Switch
开关是 UI 元素,允许用户在两种状态之间进行选择——最常见的是开/关。
useSwitch API
导入
import { useSwitch } from '@mui/base/useSwitch';
// or
import { useSwitch } from '@mui/base';通过阅读本关于最小化包大小的指南,了解差异。
| 名称 | 类型 | 描述 |
|---|---|---|
| checked | boolean | 如果 |
| defaultChecked | boolean | 默认选中状态。当组件不受控制时使用。 |
| disabled | boolean | 如果 |
| onBlur | React.FocusEventHandler | |
| onChange | React.ChangeEventHandler<HTMLInputElement> | 状态更改时触发的回调。 |
| onFocus | React.FocusEventHandler | |
| onFocusVisible | React.FocusEventHandler | |
| readOnly | boolean | 如果 |
| required | boolean | 如果 |
| 名称 | 类型 | 描述 |
|---|---|---|
| checked | boolean | 如果 |
| disabled | boolean | 如果 |
| focusVisible | boolean | 如果 |
| getInputProps | (externalProps?: React.HTMLAttributes<HTMLInputElement>) => UseSwitchInputSlotProps | 输入 slot props 的解析器。 |
| inputRef | React.RefCallback<HTMLInputElement> | null | 输入 slot 的 DOM 节点的 Ref。 |
| readOnly | boolean | 如果 |