--- title: CloseButton 关闭按钮 description: 用于关闭对话框、模态框或 dismiss 内容的按钮组件 component: close-button group: 组件 --- ## 用法 ```vue ``` ## 示例 ### 交互 ### 自定义图标 ## 自定义样式 ### Tailwind CSS ### 全局 CSS 可使用 `@layer components` 指令自定义 CloseButton 组件类。 ```css @layer components { .hv-close-button { @apply bg-red-100 text-red-800 hover:bg-red-200; } .hv-close-button--custom { @apply rounded-full border-2 border-red-300; } } ``` ## 样式参考 HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。 ### CSS 类 CloseButton 组件使用以下 CSS 类: #### 基础类 [!toc] - `.hv-close-button` - 基础组件样式 #### 变体类 [!toc] - `.hv-close-button--default` - 默认变体 ### 交互状态 组件同时支持 CSS 伪类与 data 属性: - **Hover**:`:hover` 或 `[data-hovered="true"]` - **Active/Pressed**:`:active` 或 `[data-pressed="true"]` - **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]` - **Disabled**:`:disabled` 或 `[aria-disabled="true"]` ## API 参考 ### CloseButton | Prop | 类型 | 默认值 | 描述 | | ------------ | --------------------- | ------------ | -------------------------- | | `variant` | `"default"` | `"default"` | 按钮视觉变体 | | `isDisabled` | `boolean` | `false` | 是否禁用 | | 默认插槽 | `string \| Component` | 内置关闭图标 | 显示内容(默认为关闭图标) | ### 原生按钮属性 CloseButton 是原生 `button`,`type` 固定为 `"button"`。常用属性包括: | Prop | 类型 | 描述 | | ------------------ | -------- | ------------------------------------ | | `aria-label` | `string` | 屏幕阅读器的无障碍标签,默认 `Close` | | `aria-labelledby` | `string` | 标注按钮的元素 ID | | `aria-describedby` | `string` | 描述按钮的元素 ID | ### 作用域插槽状态 | 参数 | 类型 | 描述 | | ---------------- | --------- | ---------------------- | | `isHovered` | `boolean` | 是否悬停 | | `isPressed` | `boolean` | 是否按下 | | `isFocused` | `boolean` | 是否聚焦 | | `isFocusVisible` | `boolean` | 是否显示键盘焦点指示器 | | `isDisabled` | `boolean` | 是否禁用 | `onPress` 与 React Aria 的 PressEvent 不直接等价;Vue 使用原生 `@click` 与键盘事件。默认关闭图标来自固定基线 `CloseIcon`,可通过插槽替换为任意图标组件。 ## 相关组件 [Alert 警告](./alert) · [AlertDialog 警告对话框](./alert-dialog) · [Chip 标签](./chip)