按钮
按钮让用户通过单击进行操作和选择。
useButton API
导入
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 | React.Ref<Element> | - | |
tabIndex | NonNullable<React.HTMLAttributes<any>['tabIndex']> | - | |
to | string | - | |
type | React.ButtonHTMLAttributes<HTMLButtonElement>['type'] | 'button' | 当 |
名称 | 类型 | 描述 |
---|---|---|
active | boolean | 如果 |
focusVisible | boolean | 如果 |
getRootProps | <ExternalProps extends Record<string, any> = {}>(externalProps?: ExternalProps) => UseButtonRootSlotProps<ExternalProps> | 根 slot props 的解析器。 |
rootRef | React.RefCallback<Element> | null | 组件根 DOM 元素的 ref。 |
setFocusVisible | React.Dispatch<React.SetStateAction<boolean>> | 用于设置 |