纯图标按钮
IconButton Props
IconButton 继承 Button 的大部分属性,但不提供 isIconOnly,因为它始终是纯图标模式。
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
label | string | 必需 | 按钮的无障碍名称,供辅助技术识别按钮用途。 |
variant | 'primary' | 'secondary' | 'ghost' | 'destructive' | 'secondary' | 按钮的视觉样式,同时暗示操作的类型。 |
size | 'sm' | 'md' | 'lg' | 'md' | 按钮尺寸,IconButton 始终渲染为正方形。 |
elevation | 'none' | 'low' | 'med' | 'high' | 'none' | 静止状态的阴影深度,适合悬浮于内容上方的独立按钮。 |
isDisabled | boolean | false | 是否禁用交互。存在 tooltip 时改用 aria-disabled 标记,让按钮保留焦点以显示提示。 |
isLoading | boolean | false | 是否显示加载图标,同时设置 aria-busy。加载期间默认阻止重复操作。 |
isInterruptible | boolean | false | 是否允许加载期间再次触发 clickAction。 |
clickAction | (event: MouseEvent) => void | Promise<void> | — | 点击时执行的回调;返回 Promise 时,组件会自动显示加载状态。 |
tooltip | string | — | 悬停或键盘聚焦时显示的补充提示,不能替代 label。 |
href | string | — | 链接地址。存在且未禁用时,根元素渲染为链接。 |
width | number | string | — | 按钮宽度。数字转换为像素,CSS 字符串按原样使用。 |
其他继承属性如下。完整说明见 Button 属性。
type。name。value。form。loadingLabel。as。target。rel。
插槽
- 默认插槽为必需项。
- 默认插槽必须提供一个表示操作的图标。
IconButton不提供可见文字。IconButton不提供end插槽。
无障碍名称
必须提供准确的 label。缺少 label 时,辅助技术无法确定按钮用途。
tooltip 提供补充说明。不得用 tooltip 代替 label。
事件
click 事件的参数类型为 MouseEvent。
模板引用
IconButton 公开 element。 类型为 HTMLButtonElement | HTMLAnchorElement | HTMLElement | null。
原生属性
以下内容传入根元素:
- HTML 属性。
aria-*属性。data-*属性。class。style。- 原生事件监听器。