按鈕
按鈕讓使用者透過單次點擊執行動作和做出選擇。
useButton API
Import(導入)
import { useButton } from '@mui/base/useButton';
// or
import { useButton } from '@mui/base';
請閱讀這份關於最小化套件大小的指南,以了解差異。
名稱 | 類型 | 預設值 | 描述 |
---|---|---|---|
disabled(停用) | boolean | false | 如果 |
focusableWhenDisabled(停用時可聚焦) | boolean | false | 如果 |
href | string | - | |
onFocusVisible(焦點可見時觸發) | React.FocusEventHandler | - | |
rootElementName(根元素名稱) | keyof HTMLElementTagNameMap | '' | HTML 元素,例如 'button'、'a' 等 |
rootRef(根元素 Ref) | React.Ref<Element> | - | |
tabIndex | NonNullable<React.HTMLAttributes<any>['tabIndex']> | - | |
to | string | - | |
type(類型) | React.ButtonHTMLAttributes<HTMLButtonElement>['type'] | 'button' | 當 |
名稱 | 類型 | 描述 |
---|---|---|
active(啟用) | boolean | 如果 |
focusVisible(焦點可見) | boolean | 如果 |
getRootProps(取得根元素 Props) | <ExternalProps extends Record<string, any> = {}>(externalProps?: ExternalProps) => UseButtonRootSlotProps<ExternalProps> | 根插槽 props 的解析器。 |
rootRef(根元素 Ref) | React.RefCallback<Element> | null | 元件根 DOM 元素的 ref。 |
setFocusVisible(設定焦點可見) | React.Dispatch<React.SetStateAction<boolean>> | 用於設定 |