開關
開關是一種 UI 元素,可讓使用者在兩種狀態之間做選擇,最常見的是開啟/關閉。
useSwitch API
Import
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 | 若為 |