跳到内容
+

按钮

按钮让用户通过单击进行操作和选择。

useButton API

导入

import { useButton } from '@mui/base/useButton';
// or
import { useButton } from '@mui/base';

通过阅读关于最小化包大小的指南来了解差异。

参数

名称类型默认值描述
disabledbooleanfalse

如果 true,组件将被禁用。

focusableWhenDisabledbooleanfalse

如果 true,允许禁用的按钮接收焦点。

hrefstring-
onFocusVisibleReact.FocusEventHandler-
rootElementNamekeyof HTMLElementTagNameMap''

HTML 元素,例如 'button'、'a' 等

rootRefReact.Ref<Element>-
tabIndexNonNullable<React.HTMLAttributes<any>['tabIndex']>-
tostring-
typeReact.ButtonHTMLAttributes<HTMLButtonElement>['type']'button'

componentbutton 时应用的 Type 属性。

返回值

名称类型描述
activeboolean

如果 true,组件处于激活状态(按下)。

focusVisibleboolean

如果 true,组件正在使用键盘聚焦。

getRootProps<ExternalProps extends Record<string, any> = {}>(externalProps?: ExternalProps) => UseButtonRootSlotProps<ExternalProps>

根 slot props 的解析器。

rootRefReact.RefCallback<Element> | null

组件根 DOM 元素的 ref。

setFocusVisibleReact.Dispatch<React.SetStateAction<boolean>>

用于设置 focusVisible 参数的回调。