feat: migrate button groups and toggle buttons with focus regressions
This commit is contained in:
@@ -363,3 +363,11 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
|
|||||||
- Markdown 表格类型中的管道符必须转义,即使包在行内代码中也不例外;浏览器核对每行单元格数及长短表铺满/无横向溢出。新增依赖同步 dependencies、external 策略与 dist 类型检查,不以源码 alias 验证代替发布产物。
|
- Markdown 表格类型中的管道符必须转义,即使包在行内代码中也不例外;浏览器核对每行单元格数及长短表铺满/无横向溢出。新增依赖同步 dependencies、external 策略与 dist 类型检查,不以源码 alias 验证代替发布产物。
|
||||||
|
|
||||||
- 底座的 useVModel 不能在初始无选中项时误入 passive 模式。Tabs 私有 wire key 对原始字符串/数值做类型编码,并用独立空值表示无选择;公开 key 与事件保持原值。回归初始空/全禁用→启用→受控拒绝,检查 aria-selected 与视觉标记一致。
|
- 底座的 useVModel 不能在初始无选中项时误入 passive 模式。Tabs 私有 wire key 对原始字符串/数值做类型编码,并用独立空值表示无选择;公开 key 与事件保持原值。回归初始空/全禁用→启用→受控拒绝,检查 aria-selected 与视觉标记一致。
|
||||||
|
|
||||||
|
## M26–M28 按钮组复核经验(2026-10-23)
|
||||||
|
|
||||||
|
- 成员注册必须响应 key/禁用/卸载,导航顺序遵循当前 DOM。重排测试使用稳定 VNode key,并断言按键后的具体焦点目标,不能仅检查剩余成员数或单 Tab 入口数量。
|
||||||
|
- 单 Tab 入口策略必须同步真实 focus(鼠标、调用方 focus 和内部导航),同步 active 时不再次调用 focus。RTL 回归至少三个成员,两个循环项无法区分导航正反方向。
|
||||||
|
- 受控与内部状态都需协调动态 single/multiple 切换;逻辑选择 key 与 DOM id 分离,数字/字符串键不能因序列化而混同。上下文中的尺寸/方向使用响应式值,不保存 setup 快照。
|
||||||
|
- ButtonGroup 的默认属性按上游直接子项优先级合并,区分省略与显式 false;ToggleButtonGroup 的整体禁用以及 Fieldset 强制禁用是不同契约,不统一改成同一覆盖规则。文档明确 disallowEmptySelection 只阻止用户清空已有选择,不自动产生初始值。
|
||||||
|
- M26–M28 最终验收见迁移报告;下一批待派发任务为 [M29 Toolbar](docs/migrations/M29-toolbar-prompt.md)。Toolbar 集成需明确父子焦点所有权,避免一键触发两次导航;不以相邻参考仓库作为构建依赖。
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ const groups = [
|
|||||||
{ title: "Badge 徽章", url: "/components/badge" },
|
{ title: "Badge 徽章", url: "/components/badge" },
|
||||||
{ title: "Breadcrumbs 面包屑", url: "/components/breadcrumbs" },
|
{ title: "Breadcrumbs 面包屑", url: "/components/breadcrumbs" },
|
||||||
{ title: "Button 按钮", url: "/components/button" },
|
{ title: "Button 按钮", url: "/components/button" },
|
||||||
|
{
|
||||||
|
title: "ButtonGroup 按钮组",
|
||||||
|
url: "/components/button-group",
|
||||||
|
},
|
||||||
{ title: "Card 卡片", url: "/components/card" },
|
{ title: "Card 卡片", url: "/components/card" },
|
||||||
{ title: "Checkbox 复选框", url: "/components/checkbox" },
|
{ title: "Checkbox 复选框", url: "/components/checkbox" },
|
||||||
{ title: "CheckboxGroup 复选框组", url: "/components/checkbox-group" },
|
{ title: "CheckboxGroup 复选框组", url: "/components/checkbox-group" },
|
||||||
@@ -91,6 +95,14 @@ const groups = [
|
|||||||
{ title: "TextArea 多行文本框", url: "/components/textarea" },
|
{ title: "TextArea 多行文本框", url: "/components/textarea" },
|
||||||
{ title: "TextField 文本输入框", url: "/components/text-field" },
|
{ title: "TextField 文本输入框", url: "/components/text-field" },
|
||||||
{ title: "Tooltip 工具提示", url: "/components/tooltip" },
|
{ title: "Tooltip 工具提示", url: "/components/tooltip" },
|
||||||
|
{
|
||||||
|
title: "ToggleButton 切换按钮",
|
||||||
|
url: "/components/toggle-button",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "ToggleButtonGroup 切换按钮组",
|
||||||
|
url: "/components/toggle-button-group",
|
||||||
|
},
|
||||||
{ title: "Typography 排版", url: "/components/typography" },
|
{ title: "Typography 排版", url: "/components/typography" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ description: 已迁移组件及文档
|
|||||||
- [Badge 徽章](./components/badge)
|
- [Badge 徽章](./components/badge)
|
||||||
- [Breadcrumbs 面包屑](./components/breadcrumbs)
|
- [Breadcrumbs 面包屑](./components/breadcrumbs)
|
||||||
- [Button 按钮](./components/button)
|
- [Button 按钮](./components/button)
|
||||||
|
- [ButtonGroup 按钮组](./components/button-group)
|
||||||
- [Card 卡片](./components/card)
|
- [Card 卡片](./components/card)
|
||||||
- [Chip 标签](./components/chip)
|
- [Chip 标签](./components/chip)
|
||||||
- [CloseButton 关闭按钮](./components/close-button)
|
- [CloseButton 关闭按钮](./components/close-button)
|
||||||
@@ -48,3 +49,5 @@ description: 已迁移组件及文档
|
|||||||
|
|
||||||
- [ScrollShadow 滚动阴影](./components/scroll-shadow)
|
- [ScrollShadow 滚动阴影](./components/scroll-shadow)
|
||||||
- [Tabs 标签页](./components/tabs)
|
- [Tabs 标签页](./components/tabs)
|
||||||
|
- [ToggleButton 切换按钮](./components/toggle-button)
|
||||||
|
- [ToggleButtonGroup 切换按钮组](./components/toggle-button-group)
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
---
|
||||||
|
title: ButtonGroup 按钮组
|
||||||
|
description: 将相关按钮组合在一起,保持一致的样式与间距
|
||||||
|
component: button-group
|
||||||
|
group: 组件
|
||||||
|
---
|
||||||
|
|
||||||
|
## 用法
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ButtonGroup, Button } from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-basic" />
|
||||||
|
|
||||||
|
## 组件结构
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ButtonGroup>
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
> **ButtonGroup** 将多个 Button 组合在一起,应用一致的样式、间距与自动圆角处理。它通过 provide/inject 向直接子按钮传递 `size`、`variant` 与 `isDisabled` 属性。
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|
### 变体
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-variants" />
|
||||||
|
|
||||||
|
### 尺寸
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-sizes" />
|
||||||
|
|
||||||
|
### 方向
|
||||||
|
|
||||||
|
使用 `orientation` 属性可水平或垂直排列按钮。
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-orientation" />
|
||||||
|
|
||||||
|
### 带图标
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-with-icons" />
|
||||||
|
|
||||||
|
### 宽度充满
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-full-width" />
|
||||||
|
|
||||||
|
### 禁用状态
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-disabled" />
|
||||||
|
|
||||||
|
### 无分隔线
|
||||||
|
|
||||||
|
省略按钮中的 `<ButtonGroupSeparator />` 组件即可。
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-without-separator" />
|
||||||
|
|
||||||
|
## 自定义样式
|
||||||
|
|
||||||
|
### Tailwind CSS
|
||||||
|
|
||||||
|
<ComponentPreview name="button-group-custom-styles" />
|
||||||
|
|
||||||
|
### 全局 CSS
|
||||||
|
|
||||||
|
可使用 `@layer components` 指令自定义 ButtonGroup 组件类。
|
||||||
|
|
||||||
|
```css
|
||||||
|
@layer components {
|
||||||
|
.hv-button-group {
|
||||||
|
@apply gap-2 rounded-lg;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-button-group__separator {
|
||||||
|
@apply opacity-25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 样式参考
|
||||||
|
|
||||||
|
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||||
|
|
||||||
|
### CSS 类
|
||||||
|
|
||||||
|
ButtonGroup 组件使用以下 CSS 类:
|
||||||
|
|
||||||
|
#### 基础类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-button-group` - 按钮组根容器
|
||||||
|
- `.hv-button-group--full-width` - 全宽修饰符
|
||||||
|
- `.hv-button-group__separator` - 按钮之间的分隔元素
|
||||||
|
|
||||||
|
ButtonGroup 组件自动为按钮应用圆角:
|
||||||
|
|
||||||
|
- 第一个按钮圆角左/起始边
|
||||||
|
- 最后一个按钮圆角右/结束边
|
||||||
|
- 中间按钮无圆角
|
||||||
|
- 单个按钮四边全圆角
|
||||||
|
|
||||||
|
在每个 Button 内(第一个除外)添加 `<ButtonGroupSeparator />` 以显示分隔线。
|
||||||
|
|
||||||
|
## API 参考
|
||||||
|
|
||||||
|
### ButtonGroup
|
||||||
|
|
||||||
|
| Prop | 类型 | 默认值 | 描述 |
|
||||||
|
| ------------- | --------------------------------------------------------------------------------------------- | -------------- | -------------------------------------------- |
|
||||||
|
| `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | - | 应用于组内所有直接子按钮的视觉变体 |
|
||||||
|
| `size` | `'sm' \| 'md' \| 'lg'` | - | 应用于组内所有直接子按钮的尺寸 |
|
||||||
|
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | 按钮组方向 |
|
||||||
|
| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 |
|
||||||
|
| `isDisabled` | `boolean` | `false` | 是否禁用组内所有直接子按钮(单个按钮可覆盖) |
|
||||||
|
| `as` | `string` | `'div'` | 渲染的根元素 |
|
||||||
|
| `class` | `string` | - | 附加 CSS 类 |
|
||||||
|
|
||||||
|
### ButtonGroupSeparator
|
||||||
|
|
||||||
|
| Prop | 类型 | 默认值 | 描述 |
|
||||||
|
| ------- | -------- | ------ | ----------- |
|
||||||
|
| `class` | `string` | - | 附加 CSS 类 |
|
||||||
|
|
||||||
|
## 说明
|
||||||
|
|
||||||
|
- ButtonGroup 通过 provide/inject 向**直接子 Button** 传递 `size`、`variant` 与 `isDisabled` 属性
|
||||||
|
- **仅直接子按钮接收 ButtonGroup 属性** - 嵌套在其他组件(如 Modal、Dropdown 等)内的 Button 即使位于 ButtonGroup 后代也不会继承组属性
|
||||||
|
- 单个 Button 可通过自身属性覆盖组的默认值
|
||||||
|
- 组件自动处理按钮之间的圆角
|
||||||
|
- 在每个 Button 内(第一个除外)添加 `<ButtonGroupSeparator />`,可在按钮之间显示分隔线
|
||||||
|
- 组内按钮移除 active/pressed 缩放变换,外观更统一
|
||||||
|
|
||||||
|
## 相关组件
|
||||||
|
|
||||||
|
- [Button 按钮](./button)
|
||||||
|
- [ToggleButton 切换按钮](./toggle-button)
|
||||||
|
- [ToggleButtonGroup 切换按钮组](./toggle-button-group)
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
---
|
||||||
|
title: ToggleButtonGroup 切换按钮组
|
||||||
|
description: 将多个 ToggleButton 组合为统一控件,允许用户选择单个或多个选项。
|
||||||
|
component: toggle-button-group
|
||||||
|
group: 组件
|
||||||
|
---
|
||||||
|
|
||||||
|
## 用法
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ToggleButtonGroup, ToggleButton } from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-basic" />
|
||||||
|
|
||||||
|
## 组件结构
|
||||||
|
|
||||||
|
导入 ToggleButtonGroup 组件,并使用具名子组件组合布局。
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ToggleButtonGroup selection-mode="multiple">
|
||||||
|
<ToggleButton id="first">First</ToggleButton>
|
||||||
|
<ToggleButton id="second">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="third">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|
### 尺寸
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-sizes" />
|
||||||
|
|
||||||
|
### 方向
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-orientation" />
|
||||||
|
|
||||||
|
### 宽度充满
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-full-width" />
|
||||||
|
|
||||||
|
### 禁用
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-disabled" />
|
||||||
|
|
||||||
|
### 无分隔线
|
||||||
|
|
||||||
|
省略按钮中的 `<ToggleButtonGroupSeparator />` 组件即可。
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-without-separator" />
|
||||||
|
|
||||||
|
### 分离模式
|
||||||
|
|
||||||
|
使用 `is-detached` 让按钮之间留出间隔,而不是彼此连接。
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-attached" />
|
||||||
|
|
||||||
|
### 选择模式
|
||||||
|
|
||||||
|
使用 `selection-mode="single"` 实现互斥选择,或使用 `selection-mode="multiple"` 实现独立切换。
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-selection-mode" />
|
||||||
|
|
||||||
|
### 受控组件
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-controlled" />
|
||||||
|
|
||||||
|
## 自定义样式
|
||||||
|
|
||||||
|
### Tailwind CSS
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-group-custom-styles" />
|
||||||
|
|
||||||
|
### 全局 CSS
|
||||||
|
|
||||||
|
若要自定义组件类,可使用 `@layer components` 指令。
|
||||||
|
|
||||||
|
```css
|
||||||
|
@layer components {
|
||||||
|
.hv-toggle-button-group {
|
||||||
|
@apply rounded-lg;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button-group__separator {
|
||||||
|
@apply opacity-25;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button-group--full-width {
|
||||||
|
@apply w-full;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 样式参考
|
||||||
|
|
||||||
|
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||||
|
|
||||||
|
### CSS 类
|
||||||
|
|
||||||
|
ToggleButtonGroup 组件使用以下 CSS 类:
|
||||||
|
|
||||||
|
#### 基础与布局类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-toggle-button-group` - 容器基础样式
|
||||||
|
- `.hv-toggle-button-group--horizontal` - 水平方向
|
||||||
|
- `.hv-toggle-button-group--vertical` - 垂直方向
|
||||||
|
- `.hv-toggle-button-group--full-width` - 全宽修饰符
|
||||||
|
- `.hv-toggle-button-group__separator` - 按钮之间的分隔线元素
|
||||||
|
|
||||||
|
#### 修饰符类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-toggle-button-group--detached` - 分离模式(按钮间有间隔)
|
||||||
|
|
||||||
|
## API 参考
|
||||||
|
|
||||||
|
### ToggleButtonGroup
|
||||||
|
|
||||||
|
| Prop | 类型 | 默认值 | 描述 |
|
||||||
|
| -------------------------------------- | -------------------------------------------------- | -------------- | --------------------------------------------------- |
|
||||||
|
| `selectionMode` | `'single' \| 'multiple'` | `'single'` | 是否允许选中一个或多个按钮 |
|
||||||
|
| `v-model` / `modelValue` | `string \| number \| (string \| number)[] \| null` | - | 受控选中值;single 为单个 key,multiple 为 key 数组 |
|
||||||
|
| `defaultValue` | 同上 | - | 默认选中值(非受控) |
|
||||||
|
| `selectedKeys` / `defaultSelectedKeys` | 同上 | - | 与 `modelValue`/`defaultValue` 等价的别名 |
|
||||||
|
| `disallowEmptySelection` | `boolean` | `false` | 是否禁止清空所有选中 |
|
||||||
|
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | 布局方向 |
|
||||||
|
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 传递给子 ToggleButton 的尺寸 |
|
||||||
|
| `isDetached` | `boolean` | `false` | 按钮是否以间隔分离显示 |
|
||||||
|
| `fullWidth` | `boolean` | `false` | 按钮组是否占满可用宽度 |
|
||||||
|
| `isDisabled` | `boolean` | `false` | 是否禁用组内全部按钮 |
|
||||||
|
| `as` | `string` | `'div'` | 渲染的根元素 |
|
||||||
|
|
||||||
|
### 事件
|
||||||
|
|
||||||
|
| 事件 | 参数 | 描述 |
|
||||||
|
| ------------------- | ---------------------- | --------------------------------------------- |
|
||||||
|
| `update:modelValue` | `key \| key[] \| null` | 选中变化时触发 |
|
||||||
|
| `selectionChange` | `key \| key[] \| null` | 选中变化时触发(与 `update:modelValue` 同时) |
|
||||||
|
|
||||||
|
### ToggleButtonGroupSeparator
|
||||||
|
|
||||||
|
| Prop | 类型 | 默认值 | 描述 |
|
||||||
|
| ------- | -------- | ------ | ------------- |
|
||||||
|
| `class` | `string` | - | 额外的 CSS 类 |
|
||||||
|
|
||||||
|
## 说明
|
||||||
|
|
||||||
|
- ToggleButtonGroup 使用 provide/inject 将 `size` 传递给子 ToggleButton 组件
|
||||||
|
- 每个 ToggleButton 都必须有唯一 `id`(或 `value`)prop,并与选中 key 对应
|
||||||
|
- 组的 `isDisabled` 会禁用所有子 ToggleButton;子项的 `isDisabled` 可额外禁用单个按钮,不能用 `false` 解除组禁用
|
||||||
|
- 组件会自动处理按钮之间的圆角
|
||||||
|
- 在每个 ToggleButton(第一个除外)内添加 `<ToggleButtonGroupSeparator />`,可在按钮之间显示分隔线
|
||||||
|
- `disallowEmptySelection` 阻止用户清空已有选择;需要初始选中时,请同时提供 `defaultValue` 或受控值
|
||||||
|
- `selectionMode="single"` 时根节点为 `role="radiogroup"`,按钮为 `role="radio"`;`multiple` 时为 `role="toolbar"` 与 `role="button"`
|
||||||
|
- Vue 模型使用 `modelValue`/数组,对应上游 `selectedKeys`/`Set<Key>`;React Aria 集合 API 未直接移植
|
||||||
|
|
||||||
|
## 相关组件
|
||||||
|
|
||||||
|
- [ToggleButton 切换按钮](./toggle-button)
|
||||||
|
- [ButtonGroup 按钮组](./button-group)
|
||||||
|
- [CheckboxGroup 复选框组](./checkbox-group)
|
||||||
|
- [RadioGroup 单选框组](./radio-group)
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
---
|
||||||
|
title: ToggleButton 切换按钮
|
||||||
|
description: 用于在开启/关闭或已选中/未选中状态之间切换的交互式切换控件。
|
||||||
|
component: toggle-button
|
||||||
|
group: 组件
|
||||||
|
---
|
||||||
|
|
||||||
|
## 用法
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ToggleButton } from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-basic" />
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|
### 变体
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-variants" />
|
||||||
|
|
||||||
|
### 仅图标
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-icon-only" />
|
||||||
|
|
||||||
|
### 尺寸
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-sizes" />
|
||||||
|
|
||||||
|
### 禁用
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-disabled" />
|
||||||
|
|
||||||
|
### 受控组件
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-controlled" />
|
||||||
|
|
||||||
|
## 自定义样式
|
||||||
|
|
||||||
|
### Tailwind CSS
|
||||||
|
|
||||||
|
<ComponentPreview name="toggle-button-custom-styles" />
|
||||||
|
|
||||||
|
### 全局 CSS
|
||||||
|
|
||||||
|
若要自定义组件类,可使用 `@layer components` 指令。
|
||||||
|
|
||||||
|
```css
|
||||||
|
@layer components {
|
||||||
|
.hv-toggle-button {
|
||||||
|
@apply bg-purple-500 text-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button--icon-only {
|
||||||
|
@apply rounded-lg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 样式参考
|
||||||
|
|
||||||
|
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||||
|
|
||||||
|
### CSS 类
|
||||||
|
|
||||||
|
ToggleButton 组件使用以下 CSS 类:
|
||||||
|
|
||||||
|
#### 基础与尺寸类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-toggle-button` - 切换按钮基础样式
|
||||||
|
- `.hv-toggle-button--sm` - 小尺寸变体
|
||||||
|
- `.hv-toggle-button--md` - 中尺寸变体(默认)
|
||||||
|
- `.hv-toggle-button--lg` - 大尺寸变体
|
||||||
|
|
||||||
|
#### 变体类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-toggle-button--default` - 默认变体(填充背景)
|
||||||
|
- `.hv-toggle-button--ghost` - 幽灵变体(透明背景)
|
||||||
|
|
||||||
|
#### 修饰符类 [!toc]
|
||||||
|
|
||||||
|
- `.hv-toggle-button--icon-only` - 仅图标切换按钮
|
||||||
|
- `.hv-toggle-button--icon-only.hv-toggle-button--sm` - 小尺寸仅图标
|
||||||
|
- `.hv-toggle-button--icon-only.hv-toggle-button--lg` - 大尺寸仅图标
|
||||||
|
|
||||||
|
### 交互状态
|
||||||
|
|
||||||
|
该切换按钮同时支持 CSS 伪类与 data 属性,以便灵活控制状态:
|
||||||
|
|
||||||
|
- **已选中**:`[data-selected="true"]`(强调色背景与前景)
|
||||||
|
- **悬停**`:hover` 或 `[data-hovered="true"]`
|
||||||
|
- **激活/按下**:`:active` 或 `[data-pressed="true"]`(包含缩放变换)
|
||||||
|
- **聚焦**:`:focus-visible` 或 `[data-focus-visible="true"]`(显示焦点环)
|
||||||
|
- **禁用**:`:disabled` 或 `[data-disabled="true"]`(降低透明度,禁用指针事件)
|
||||||
|
|
||||||
|
## API 参考
|
||||||
|
|
||||||
|
### ToggleButton
|
||||||
|
|
||||||
|
| Prop | 类型 | 默认值 | 描述 |
|
||||||
|
| ---------------------------------- | ---------------------- | ----------- | --------------------------------------------- |
|
||||||
|
| `variant` | `'default' \| 'ghost'` | `'default'` | 视觉样式变体 |
|
||||||
|
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 切换按钮尺寸 |
|
||||||
|
| `isIconOnly` | `boolean` | `false` | 按钮是否仅包含图标 |
|
||||||
|
| `v-model` / `modelValue` | `boolean` | - | 受控的已选中状态 |
|
||||||
|
| `isSelected` | `boolean` | - | 受控的已选中状态(与 `modelValue` 等价别名) |
|
||||||
|
| `defaultValue` / `defaultSelected` | `boolean` | `false` | 默认已选中状态(非受控) |
|
||||||
|
| `isDisabled` | `boolean` | `false` | 是否禁用切换按钮 |
|
||||||
|
| `id` | `string \| number` | - | 组内成员键,对应 ToggleButtonGroup 的选中 key |
|
||||||
|
| `value` | `string \| number` | - | 与 `id` 等价的组内成员键 |
|
||||||
|
| `asChild` | `boolean` | `false` | 将属性与交互合并到默认插槽中唯一的原生 button |
|
||||||
|
|
||||||
|
### 事件
|
||||||
|
|
||||||
|
| 事件 | 参数 | 描述 |
|
||||||
|
| ------------------- | --------- | --------------------------------------------------- |
|
||||||
|
| `update:modelValue` | `boolean` | 已选中状态变化时触发 |
|
||||||
|
| `change` | `boolean` | 已选中状态变化时触发(与 `update:modelValue` 同时) |
|
||||||
|
|
||||||
|
### 作用域插槽
|
||||||
|
|
||||||
|
| 名称 | 参数 | 描述 |
|
||||||
|
| --------- | ----------------------------------------------------------------------------- | ------------------ |
|
||||||
|
| `default` | `{ isSelected, isPressed, isHovered, isFocused, isFocusVisible, isDisabled }` | 按钮内容与渲染状态 |
|
||||||
|
|
||||||
|
## 说明
|
||||||
|
|
||||||
|
- 独立使用时通过 `v-model` 或 `isSelected`/`change` 控制选中状态,对应上游 `isSelected`/`defaultSelected`/`onChange`
|
||||||
|
- 在 `ToggleButtonGroup` 内使用时,需提供唯一 `id`(或 `value`)作为选中 key;组内 `size` 可被继承
|
||||||
|
- `selectionMode="single"` 的组内按钮渲染为 `role="radio"` 并同步 `aria-checked`;其余情况为 `role="button"` 与 `aria-pressed`
|
||||||
|
- React Aria 的 `onPress`/`PressEvent` 与渲染函数 props 由 `@click` 与作用域插槽适配
|
||||||
|
|
||||||
|
## 相关组件
|
||||||
|
|
||||||
|
- [ToggleButtonGroup 切换按钮组](./toggle-button-group)
|
||||||
|
- [ButtonGroup 按钮组](./button-group)
|
||||||
|
- [Switch 开关](./switch)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<ButtonGroup>
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<ButtonGroup class="gap-2 rounded-lg">
|
||||||
|
<Button class="rounded-lg">First</Button>
|
||||||
|
<Button class="rounded-lg">
|
||||||
|
<ButtonGroupSeparator class="opacity-25" />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button class="rounded-lg">
|
||||||
|
<ButtonGroupSeparator class="opacity-25" />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<ButtonGroup is-disabled>
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="w-full max-w-md">
|
||||||
|
<ButtonGroup full-width>
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="demo-row">
|
||||||
|
<ButtonGroup orientation="horizontal">
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
<ButtonGroup orientation="vertical">
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const sizes = [
|
||||||
|
{ size: "sm", label: "Small" },
|
||||||
|
{ size: "md", label: "Medium (default)" },
|
||||||
|
{ size: "lg", label: "Large" },
|
||||||
|
] as const;
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full flex-col gap-6">
|
||||||
|
<div v-for="item in sizes" :key="item.size" class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">{{ item.label }}</p>
|
||||||
|
<ButtonGroup :size="item.size">
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
|
||||||
|
const variants = [
|
||||||
|
"primary",
|
||||||
|
"secondary",
|
||||||
|
"tertiary",
|
||||||
|
"outline",
|
||||||
|
"ghost",
|
||||||
|
"danger",
|
||||||
|
] as const;
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full flex-col gap-6">
|
||||||
|
<div v-for="variant in variants" :key="variant" class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">{{ variant }}</p>
|
||||||
|
<ButtonGroup :variant="variant">
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Second
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
Third
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import { IconWorld, IconPlus, IconTrash } from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full flex-col gap-6">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">With icons</p>
|
||||||
|
<ButtonGroup variant="secondary">
|
||||||
|
<Button>
|
||||||
|
<IconWorld aria-hidden="true" />
|
||||||
|
Search
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
<IconPlus aria-hidden="true" />
|
||||||
|
Add
|
||||||
|
</Button>
|
||||||
|
<Button>
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
<IconTrash aria-hidden="true" />
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Icon only buttons</p>
|
||||||
|
<ButtonGroup variant="tertiary">
|
||||||
|
<Button is-icon-only aria-label="Search">
|
||||||
|
<IconWorld aria-hidden="true" />
|
||||||
|
</Button>
|
||||||
|
<Button is-icon-only aria-label="Add">
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
<IconPlus aria-hidden="true" />
|
||||||
|
</Button>
|
||||||
|
<Button is-icon-only aria-label="Delete">
|
||||||
|
<ButtonGroupSeparator />
|
||||||
|
<IconTrash aria-hidden="true" />
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ButtonGroup, Button } from "@heroui-vue/components";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<ButtonGroup>
|
||||||
|
<Button>First</Button>
|
||||||
|
<Button>Second</Button>
|
||||||
|
<Button>Third</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from "vue";
|
||||||
|
import { ToggleButton } from "@heroui-vue/components";
|
||||||
|
import { IconHeart, IconHeartFilled } from "@tabler/icons-vue";
|
||||||
|
|
||||||
|
const liked = ref(false);
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<ToggleButton v-model="liked">
|
||||||
|
<IconHeartFilled v-if="liked" aria-hidden="true" />
|
||||||
|
<IconHeart v-else aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton variant="ghost">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from "vue";
|
||||||
|
import { ToggleButton } from "@heroui-vue/components";
|
||||||
|
import { IconHeart, IconHeartFilled } from "@tabler/icons-vue";
|
||||||
|
|
||||||
|
const isSelected = ref(false);
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<ToggleButton v-model="isSelected">
|
||||||
|
<IconHeartFilled v-if="isSelected" aria-hidden="true" />
|
||||||
|
<IconHeart v-else aria-hidden="true" />
|
||||||
|
{{ isSelected ? "Liked" : "Like" }}
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
<p class="text-sm text-muted">
|
||||||
|
Status:
|
||||||
|
<span class="font-medium">
|
||||||
|
{{ isSelected ? "Selected" : "Not selected" }}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ToggleButton } from "@heroui-vue/components";
|
||||||
|
import { IconHeart } from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<ToggleButton class="rounded-lg bg-purple-500 text-white">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ToggleButton } from "@heroui-vue/components";
|
||||||
|
import { IconHeart, IconHeartFilled } from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<ToggleButton is-disabled>
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton default-selected is-disabled>
|
||||||
|
<IconHeartFilled aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full flex-col gap-6">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Attached (default)</p>
|
||||||
|
<ToggleButtonGroup selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="strikethrough"
|
||||||
|
is-icon-only
|
||||||
|
aria-label="Strikethrough"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Detached</p>
|
||||||
|
<ToggleButtonGroup is-detached selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="strikethrough"
|
||||||
|
is-icon-only
|
||||||
|
aria-label="Strikethrough"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<ToggleButtonGroup selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="strikethrough" is-icon-only aria-label="Strikethrough">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from "vue";
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
|
||||||
|
const selectedKeys = ref<(string | number)[]>(["bold"]);
|
||||||
|
const label = computed(() =>
|
||||||
|
selectedKeys.value.length ? selectedKeys.value.join(", ") : "None",
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<ToggleButtonGroup v-model="selectedKeys" selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="strikethrough" is-icon-only aria-label="Strikethrough">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
<p class="text-sm text-muted">
|
||||||
|
Selected:
|
||||||
|
<span class="font-medium">{{ label }}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<ToggleButtonGroup class="rounded-lg" selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only class="rounded-lg" aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="italic"
|
||||||
|
is-icon-only
|
||||||
|
class="rounded-lg"
|
||||||
|
aria-label="Italic"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator class="opacity-25" />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="underline"
|
||||||
|
is-icon-only
|
||||||
|
class="rounded-lg"
|
||||||
|
aria-label="Underline"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator class="opacity-25" />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="strikethrough"
|
||||||
|
is-icon-only
|
||||||
|
class="rounded-lg"
|
||||||
|
aria-label="Strikethrough"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator class="opacity-25" />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import { IconBold, IconItalic, IconUnderline } from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full flex-col gap-6">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">All buttons disabled</p>
|
||||||
|
<ToggleButtonGroup is-disabled selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Individual button disabled</p>
|
||||||
|
<ToggleButtonGroup selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only is-disabled aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="w-full max-w-md">
|
||||||
|
<ToggleButtonGroup full-width selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="strikethrough" is-icon-only aria-label="Strikethrough">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex items-start gap-8">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Horizontal</p>
|
||||||
|
<ToggleButtonGroup orientation="horizontal" selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="strikethrough"
|
||||||
|
is-icon-only
|
||||||
|
aria-label="Strikethrough"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Vertical</p>
|
||||||
|
<ToggleButtonGroup orientation="vertical" selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="strikethrough"
|
||||||
|
is-icon-only
|
||||||
|
aria-label="Strikethrough"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconAlignLeft,
|
||||||
|
IconAlignCenter,
|
||||||
|
IconAlignRight,
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full flex-col gap-6">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Single selection</p>
|
||||||
|
<ToggleButtonGroup default-selected-keys="center" selection-mode="single">
|
||||||
|
<ToggleButton id="left">
|
||||||
|
<IconAlignLeft aria-hidden="true" />
|
||||||
|
Left
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="center">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconAlignCenter aria-hidden="true" />
|
||||||
|
Center
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="right">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconAlignRight aria-hidden="true" />
|
||||||
|
Right
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Multiple selection</p>
|
||||||
|
<ToggleButtonGroup
|
||||||
|
:default-selected-keys="['bold', 'underline']"
|
||||||
|
selection-mode="multiple"
|
||||||
|
>
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="strikethrough"
|
||||||
|
is-icon-only
|
||||||
|
aria-label="Strikethrough"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
|
||||||
|
const sizes = [
|
||||||
|
{ size: "sm", label: "Small" },
|
||||||
|
{ size: "md", label: "Medium (default)" },
|
||||||
|
{ size: "lg", label: "Large" },
|
||||||
|
] as const;
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full flex-col gap-6">
|
||||||
|
<div v-for="item in sizes" :key="item.size" class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">{{ item.label }}</p>
|
||||||
|
<ToggleButtonGroup selection-mode="multiple" :size="item.size">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
id="strikethrough"
|
||||||
|
is-icon-only
|
||||||
|
aria-label="Strikethrough"
|
||||||
|
>
|
||||||
|
<ToggleButtonGroupSeparator />
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ToggleButtonGroup, ToggleButton } from "@heroui-vue/components";
|
||||||
|
import {
|
||||||
|
IconBold,
|
||||||
|
IconItalic,
|
||||||
|
IconUnderline,
|
||||||
|
IconStrikethrough,
|
||||||
|
} from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<ToggleButtonGroup selection-mode="multiple">
|
||||||
|
<ToggleButton id="bold" is-icon-only aria-label="Bold">
|
||||||
|
<IconBold aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="italic" is-icon-only aria-label="Italic">
|
||||||
|
<IconItalic aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="underline" is-icon-only aria-label="Underline">
|
||||||
|
<IconUnderline aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton id="strikethrough" is-icon-only aria-label="Strikethrough">
|
||||||
|
<IconStrikethrough aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ToggleButton } from "@heroui-vue/components";
|
||||||
|
import { IconHeart, IconBookmark } from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<ToggleButton is-icon-only aria-label="Like">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton is-icon-only variant="ghost" aria-label="Bookmark">
|
||||||
|
<IconBookmark aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ToggleButton } from "@heroui-vue/components";
|
||||||
|
import { IconHeart } from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<ToggleButton size="sm">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
Small
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton size="md">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
Medium
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton size="lg">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
Large
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<ToggleButton is-icon-only size="sm" aria-label="Small">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton is-icon-only size="md" aria-label="Medium">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton is-icon-only size="lg" aria-label="Large">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ToggleButton } from "@heroui-vue/components";
|
||||||
|
import { IconHeart, IconHeartFilled } from "@tabler/icons-vue";
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Default</p>
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<ToggleButton>
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton default-selected>
|
||||||
|
<IconHeartFilled aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p class="text-sm font-medium text-muted">Ghost</p>
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<ToggleButton variant="ghost">
|
||||||
|
<IconHeart aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton variant="ghost" default-selected>
|
||||||
|
<IconHeartFilled aria-hidden="true" />
|
||||||
|
Like
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
||||||
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
|
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
|
||||||
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
||||||
| button-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
|
||||||
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
||||||
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
|
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
|
||||||
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
||||||
@@ -44,13 +44,13 @@
|
|||||||
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
||||||
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
||||||
| toast | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| toast | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| toggle-button | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
|
||||||
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
|
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
|
||||||
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
|
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
|
||||||
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
|
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
|
||||||
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| toggle-button-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
|
||||||
| toolbar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
| toolbar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||||
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
|
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
|
||||||
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
||||||
@@ -100,7 +100,7 @@ React Aria 专属 rac 导出与 React 图标类型不移植;Vue 版 ConfigProv
|
|||||||
|
|
||||||
## 已实现组件的文档清单复核
|
## 已实现组件的文档清单复核
|
||||||
|
|
||||||
Button 14 / 14,Card 7 / 7,Input 7 / 7,Switch 15 / 15,Surface 4 / 4,Link 6 / 6,Spinner 5 / 5,CloseButton 4 / 4,Avatar 7 / 7,AvatarGroup 7 / 7,Skeleton 8 / 8,Separator 7 / 7,Kbd 7 / 7,Chip 5 / 5,Badge 8 / 8,Alert 2 / 2,InputGroup 21 / 21,TextField 13 / 13,Label 2 / 2,Description 2 / 2,FieldError 2 / 2,TextArea 7 / 7,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。
|
Button 14 / 14,ButtonGroup 9 / 9,ToggleButton 7 / 7,ToggleButtonGroup 10 / 10,Card 7 / 7,Input 7 / 7,Switch 15 / 15,Surface 4 / 4,Link 6 / 6,Spinner 5 / 5,CloseButton 4 / 4,Avatar 7 / 7,AvatarGroup 7 / 7,Skeleton 8 / 8,Separator 7 / 7,Kbd 7 / 7,Chip 5 / 5,Badge 8 / 8,Alert 2 / 2,InputGroup 21 / 21,TextField 13 / 13,Label 2 / 2,Description 2 / 2,FieldError 2 / 2,TextArea 7 / 7,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。
|
||||||
|
|
||||||
Card 图片、头像、横向布局、表单与自定义样式已补齐;Input 的标签、类型、宽度与自定义样式已对齐。Switch 补齐图标、位置、分组、表单、状态插槽与自定义根容器。Surface 覆盖变体与表单组合;Link 覆盖图标位置、文本装饰、自定义图标、asChild 与自定义样式;Spinner 覆盖颜色、尺寸、速度与自定义样式。CloseButton 覆盖默认、交互、自定义图标与自定义样式。Avatar 覆盖基本、尺寸、颜色、变体、回退、自定义图片组件与自定义样式;AvatarGroup 覆盖基本、max、自定义计数、尺寸、网格、叠放样式与自定义样式;Skeleton 覆盖文本、用户资料、列表、网格、单次闪烁、动画类型与自定义样式。Separator 覆盖基本、变体、Surface 组合、垂直、带内容布局、asChild 自定义根与自定义样式;Kbd 覆盖基本、变体、导航键、行内、说明文字、特殊键与自定义样式;Chip 覆盖基本、变体矩阵、状态图标、带图标与自定义样式。Badge 覆盖基本、变体、尺寸、颜色、四角位置、点状、带内容与自定义样式;Alert 覆盖六种组合的基本示例与自定义样式。
|
Card 图片、头像、横向布局、表单与自定义样式已补齐;Input 的标签、类型、宽度与自定义样式已对齐。Switch 补齐图标、位置、分组、表单、状态插槽与自定义根容器。Surface 覆盖变体与表单组合;Link 覆盖图标位置、文本装饰、自定义图标、asChild 与自定义样式;Spinner 覆盖颜色、尺寸、速度与自定义样式。CloseButton 覆盖默认、交互、自定义图标与自定义样式。Avatar 覆盖基本、尺寸、颜色、变体、回退、自定义图片组件与自定义样式;AvatarGroup 覆盖基本、max、自定义计数、尺寸、网格、叠放样式与自定义样式;Skeleton 覆盖文本、用户资料、列表、网格、单次闪烁、动画类型与自定义样式。Separator 覆盖基本、变体、Surface 组合、垂直、带内容布局、asChild 自定义根与自定义样式;Kbd 覆盖基本、变体、导航键、行内、说明文字、特殊键与自定义样式;Chip 覆盖基本、变体矩阵、状态图标、带图标与自定义样式。Badge 覆盖基本、变体、尺寸、颜色、四角位置、点状、带内容与自定义样式;Alert 覆盖六种组合的基本示例与自定义样式。
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,200 @@
|
|||||||
|
# M26–M28 ButtonGroup / ToggleButton / ToggleButtonGroup
|
||||||
|
|
||||||
|
基线:HeroUI 3.2.6(`ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`)。
|
||||||
|
|
||||||
|
## 上游能力与示例清单
|
||||||
|
|
||||||
|
### ButtonGroup(9 个基线预览)
|
||||||
|
|
||||||
|
| 预览 | 说明 |
|
||||||
|
| ------------------------------ | ----------------------------------------------- |
|
||||||
|
| button-group-basic | 三按钮 + Separator |
|
||||||
|
| button-group-variants | primary/secondary/tertiary/outline/ghost/danger |
|
||||||
|
| button-group-sizes | sm/md/lg |
|
||||||
|
| button-group-orientation | horizontal/vertical |
|
||||||
|
| button-group-with-icons | 图标按钮与仅图标 |
|
||||||
|
| button-group-full-width | 容器内全宽 |
|
||||||
|
| button-group-disabled | 组禁用 |
|
||||||
|
| button-group-without-separator | 无分隔线 |
|
||||||
|
| button-group-custom-styles | 自定义类 |
|
||||||
|
|
||||||
|
上游子部件:`ButtonGroup`、`ButtonGroup.Separator`。公开属性:`variant`、`size`、`orientation`、`fullWidth`、`isDisabled`、`className`。通过 Context 仅向**直接子 Button** 传递 `size`/`variant`/`isDisabled`/`fullWidth`;嵌套 Button 不继承。Separator 置于 Button 内容内(绝对定位)。CSS 自动处理首尾圆角与 outline 相邻边框。
|
||||||
|
|
||||||
|
### ToggleButton(7 个基线预览)
|
||||||
|
|
||||||
|
| 预览 | 说明 |
|
||||||
|
| --------------------------- | ------------- |
|
||||||
|
| toggle-button-basic | 独立切换 |
|
||||||
|
| toggle-button-variants | default/ghost |
|
||||||
|
| toggle-button-icon-only | 仅图标 |
|
||||||
|
| toggle-button-sizes | sm/md/lg |
|
||||||
|
| toggle-button-disabled | 禁用 |
|
||||||
|
| toggle-button-controlled | 受控 |
|
||||||
|
| toggle-button-custom-styles | 自定义类 |
|
||||||
|
|
||||||
|
上游属性:`variant`(default/ghost)、`size`、`isIconOnly`、`isSelected`/`defaultSelected`/`onChange`、`isDisabled`、`onPress`、渲染 props。状态:`data-selected`、`data-hovered`、`data-pressed`、`data-focus-visible`、`:disabled`/`aria-disabled`。
|
||||||
|
|
||||||
|
### ToggleButtonGroup(10 个基线预览)
|
||||||
|
|
||||||
|
| 预览 | 说明 |
|
||||||
|
| ------------------------------------- | --------------------- |
|
||||||
|
| toggle-button-group-basic | 工具栏式多选 |
|
||||||
|
| toggle-button-group-sizes | 组 size 传递 |
|
||||||
|
| toggle-button-group-orientation | 水平/垂直 |
|
||||||
|
| toggle-button-group-full-width | 全宽 |
|
||||||
|
| toggle-button-group-disabled | 组禁用/单独禁用 |
|
||||||
|
| toggle-button-group-without-separator | 无分隔线 |
|
||||||
|
| toggle-button-group-attached | attached / isDetached |
|
||||||
|
| toggle-button-group-selection-mode | single / multiple |
|
||||||
|
| toggle-button-group-controlled | 受控 keys |
|
||||||
|
| toggle-button-group-custom-styles | 自定义类 |
|
||||||
|
|
||||||
|
上游属性:`selectionMode`、`selectedKeys`/`defaultSelectedKeys`/`onSelectionChange`、`disallowEmptySelection`、`orientation`、`size`、`isDetached`、`fullWidth`、`isDisabled`。`multiple` → `role=toolbar` + `aria-pressed`;`single` → `role=radiogroup` + `role=radio`/`aria-checked`。成员 `id` 即选中 key。
|
||||||
|
|
||||||
|
## 实现与 Vue 差异
|
||||||
|
|
||||||
|
- **ButtonGroup**:`ButtonGroup.vue` 克隆直接子组件并注入 `__button_group_child`(与 AvatarGroup 相同模式);`Button.vue` 仅在该标记存在时合并组上下文,直接 props 优先。Separator 为 `ButtonGroupSeparator.vue`,通过 inject 取 separator 类。
|
||||||
|
- **ToggleButton**:`ToggleButton.vue` 自持 hover/press/focus 状态钩子,选中态支持 `v-model`/`modelValue`/`isSelected`/`change`。组内通过 `id`/`value` 注册成员。
|
||||||
|
- **ToggleButtonGroup**:未直接使用 Reka `ToggleGroup`。原因:Reka 固定 `role=group`,且 `useSingleOrMultipleValue` 不支持 `disallowEmptySelection`,无法满足上游 toolbar/radiogroup 与“禁止清空”语义。改为自实现轻量选择内核(`useToggleButtonSelection` + `useToggleRovingFocus`),不复制 Button 事件内核、不新增依赖、不改共享字段/choice 协议。
|
||||||
|
- **事件模型**:上游 `onChange`/`onSelectionChange` 映射为 `change` / `update:modelValue` + `selectionChange`。`onPress` 由 `click` 适配(与既有 Button 约定一致)。
|
||||||
|
- **选中 key 模型**:上游 `Set<Key>` → Vue `string | number`(single)或 `(string | number)[]`(multiple)。`number` 与 `string` 同文不同型不合并(回归已覆盖)。空选择表示为 `null`(single)或 `[]`(multiple)。
|
||||||
|
- **渲染 props**:映射为作用域插槽(`isSelected`/`isPressed`/`isHovered`/`isFocused`/`isFocusVisible`/`isDisabled`)。
|
||||||
|
- **图标**:演示使用 Tabler 官方 Vue 图标(`IconHeart`、`IconBold` 等),不自绘 SVG。
|
||||||
|
- **样式**:移植基线 CSS 与 tv 变体,类名前缀 `hv-`;`.button--outline` 选择器映射为 `.hv-button--outline`。
|
||||||
|
|
||||||
|
## 共享文件改动
|
||||||
|
|
||||||
|
| 文件 | 改动 |
|
||||||
|
| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| `packages/vue/src/components/button/Button.vue` | 增加 `__button_group_child` 标记;直接子级合并 ButtonGroup 的 size/variant/fullWidth/isDisabled;`withDefaults` 将 size/variant/fullWidth 默认设为 `undefined` 以便正确回落到组上下文 |
|
||||||
|
| `packages/styles/src/index.ts` | 追加 buttonGroup/toggleButton/toggleButtonGroup 变体 |
|
||||||
|
| `packages/styles/index.css` | 引入三个新 CSS |
|
||||||
|
| `packages/vue/src/index.ts` / `types.ts` | 导出组件、变体与 Props 类型 |
|
||||||
|
| `apps/docs/.vitepress/theme/Layout.vue` / `components.md` | 侧栏与总览导航 |
|
||||||
|
| `package.json` | `test:unit` 追加 `tests/button-toggle.test.ts` |
|
||||||
|
|
||||||
|
未改动 field/choice/Form/Fieldset/Label/Link/CloseButton 共享协议。
|
||||||
|
|
||||||
|
## 测试结果
|
||||||
|
|
||||||
|
| 命令 | 结果 |
|
||||||
|
| ----------------------- | ----------------------------------------------------------------------------------- |
|
||||||
|
| `pnpm test` | 25 文件 / **426** 通过(含 node SSR:`tests/ssr.test.ts` 12 项,其中 1 项覆盖本批) |
|
||||||
|
| `pnpm test:unit` | 24 文件 / **414** 通过(含本批 返修前 31 项) |
|
||||||
|
| `pnpm typecheck` | 通过(含 `tests/types/button-toggle-contract.ts` 合法/非法用例) |
|
||||||
|
| `pnpm build:docs` | 通过 |
|
||||||
|
| `pnpm build:playground` | 通过 |
|
||||||
|
| `pnpm format` | 通过 |
|
||||||
|
| `git diff --check` | 通过 |
|
||||||
|
|
||||||
|
本批新增 `tests/button-toggle.test.ts`(返修前 31 项;两次返修后 button-toggle 40 + probe 12 = 52 项):ButtonGroup DOM/继承/覆盖/嵌套不继承/单次点击;ToggleButton ARIA、受控/非受控、hover/press、键盘、禁用;ToggleButtonGroup 分离/全宽/方向、multiple+toolbar、single+radiogroup、disallowEmptySelection、key 身份、动态成员、组禁用、size 继承、演示清单对齐。
|
||||||
|
|
||||||
|
dist 声明已抽查:`ButtonGroup`/`ToggleButton`/`ToggleButtonGroup` 及对应 Props/变体类型可从包入口解析。
|
||||||
|
|
||||||
|
## 浏览器验证范围
|
||||||
|
|
||||||
|
已在 5173 文档站用 DOM 快照抽查三页:
|
||||||
|
|
||||||
|
- `/components/button-group`:标题、用法、9 个预览区块、变体/尺寸/方向/图标/全宽/禁用/无分隔线结构均渲染;按钮文案与 Separator 节点存在。
|
||||||
|
- `/components/toggle-button`:变体区 `[pressed]` 状态正确;禁用按钮带 `disabled`;受控示例存在。
|
||||||
|
- `/components/toggle-button-group`:`multiple` 预览根节点为 `role=toolbar`,成员为 button;sizes/orientation 等区块存在。
|
||||||
|
|
||||||
|
本轮 IAB 合成层截图失败、`scrollIntoView` 后几何坐标仍异常,未能完成真实指针点击与像素级视觉确认。交互与键盘行为以单元回归为准(返修前 31 项;两次返修后 button-toggle 40 + probe 12 = 52 项)。留给集成人抽查:
|
||||||
|
|
||||||
|
- 圆角衔接、outline 边框、垂直排列、禁用不响应
|
||||||
|
- 选中背景色、焦点环、受控文案同步
|
||||||
|
- single/multiple 角色切换、方向键移动、disallowEmptySelection、detached 间距
|
||||||
|
|
||||||
|
## 尚未验证 / 未解决
|
||||||
|
|
||||||
|
- 未做与 React 文档站的逐像素对比;不宣称视觉完全一致。
|
||||||
|
- 未做读屏、RTL、Nuxt 水合、打包后独立安装验证。
|
||||||
|
- Reka `ToggleGroup` 与上游 `ToggleButtonGroup` 的 ARIA 差异见上文;若后续统一底座,需重新评估 toolbar/radiogroup 与 `disallowEmptySelection`。
|
||||||
|
- `onPress`/`PressEvent`、React 集合 API(`ListLayout` 等)未移植。
|
||||||
|
- ButtonGroup 的 `BUTTON_GROUP_CHILD` 与 ToggleButton 的组内 `id` 约定为 Vue 化实现,API 名称已在文档中标注映射关系。
|
||||||
|
|
||||||
|
## 返修记录(2026-10-23,针对 M26-M28-review.md)
|
||||||
|
|
||||||
|
复核探针 `tests/m26-review.probe.test.ts` 原 9/10 失败,现 **10/10 通过**;已纳入 `test:unit`,未删改断言。
|
||||||
|
|
||||||
|
### 七项修复
|
||||||
|
|
||||||
|
1. **事件取消(P1)**:`ToggleButton.request` 与组 `keydown` 开头检查 `event.defaultPrevented`;调用方 `@click.prevent` / `@keydown.prevent` 不再触发选择或焦点移动。独立、组内均覆盖;避免重复回调(单入口 `request`)。
|
||||||
|
2. **multiple→single 协调(P1)**:`useToggleButtonSelection` 监听 `isSingle`,非受控内部状态折叠为最多一个 key;受控模式只读外部值,父级拒绝更新时不写回内部。
|
||||||
|
3. **焦点注册与 Tab(P1)**:成员 Map 改为显式 `version` 响应式失效;`groupKey` 变化时重新注册;禁用首项时启用项获得 `tabindex=0`;采用**单 Tab 入口**(组内仅 1 个 `tabindex=0`),方向键在组内移动,Tab 跳出组。DOM 重排、移除当前项已有回归。
|
||||||
|
4. **逻辑 key 与 DOM id(P2)**:组内 `id`/`value` 仅作逻辑键,不再写入 DOM id;独立按钮保留用户 `id`。数字 `1` 与字符串 `"1"` 不再产生重复 `id`。SSR 回归见 `tests/ssr.test.ts`。
|
||||||
|
5. **响应式 size 继承(P2)**:组上下文 `size` 改为 `computed`;子项显式 `size` 优先,取消覆盖后恢复继承(有回归)。
|
||||||
|
6. **orientation / RTL(P2)**:水平组仅处理 ArrowLeft/Right 且 `dir=rtl` 反转;垂直组仅 ArrowUp/Down;无关轴不 `preventDefault`、不移动焦点。尊重 `defaultPrevented`。
|
||||||
|
7. **ButtonGroup 禁用优先级(P2)**:改为上游空值优先级 `isDisabled ?? disabled ?? group`;显式 `false` 可覆盖组默认;`useInheritedDisabled` 仍强制 Fieldset/原生禁用。
|
||||||
|
|
||||||
|
### 回归与命令(返修后)
|
||||||
|
|
||||||
|
| 命令 | 结果 |
|
||||||
|
| -------------------------------------- | -------------------------------------------------------- |
|
||||||
|
| `pnpm test` | 26 文件 / **446** 通过(含 SSR 14) |
|
||||||
|
| `pnpm test:unit` | 25 文件 / **432** 通过(含 probe 10 + button-toggle 39) |
|
||||||
|
| `pnpm typecheck` | 通过 |
|
||||||
|
| `pnpm build:docs` / `build:playground` | 通过 |
|
||||||
|
| `pnpm format` / `git diff --check` | 通过 |
|
||||||
|
|
||||||
|
- 26 个演示均真实 `import` + `mount`,无 Vue warning(`tests/button-toggle.test.ts`)。
|
||||||
|
- 发布类型正反例:`tests/types/button-toggle-contract.ts`(typecheck 覆盖)。
|
||||||
|
- 打包产物独立消费:本轮未在工作区外新建消费工程;`build` 后 dist 声明可解析(已抽查入口导出)。未宣称“独立安装验收完成”。
|
||||||
|
|
||||||
|
### 浏览器(返修后)
|
||||||
|
|
||||||
|
- 5173 DOM 检查:每组仅 1 个 `tabindex=0`,其余 `-1`;`selection-mode` 单选预览为 `role=radiogroup`,其余 `role=toolbar`;根节点 `dir=ltr`。
|
||||||
|
- IAB 合成层仍无法稳定 click/press,键盘/指针交互以单元回归为准。RTL 方向键有单元回归,未做真实 RTL 浏览器点击。
|
||||||
|
|
||||||
|
### 仍存在的差异 / 未完成
|
||||||
|
|
||||||
|
- 未做逐像素对比、读屏、Nuxt 水合、发布到 npm 的独立安装消费。
|
||||||
|
- Reka `RovingFocusGroup` 未直接采用(需 Collection 与 Toolbar 集成);本批自实现单 Tab 入口,与上游 toolbar 的 Tab 跳转策略等价接受(探针允许二选一)。
|
||||||
|
- `onPress`/`PressEvent`、React 集合 API 未移植。
|
||||||
|
|
||||||
|
实现者不自行提交;交回复核。
|
||||||
|
|
||||||
|
## 第二次返修(2026-10-23,针对 M26-M28-review-2.md)
|
||||||
|
|
||||||
|
复核探针增至 12 项(原 10 通过 + 新增 2 失败),现 **12/12 通过**。
|
||||||
|
|
||||||
|
### 两项焦点修复
|
||||||
|
|
||||||
|
1. **P1 带 key 的 DOM 重排**:`ordered()` 改为按 `compareDocumentPosition` 的**实时 DOM 顺序**排序,不再使用 Map 插入顺序。Vue 复用并移动带 `:key` 子项后,方向键跟随新邻居;嵌套组各自独立;禁用项跳过。正式回归 `arrow navigation follows keyed DOM order after a reorder` 断言 c/b/a 重排后 ArrowRight/End/Home 的具体目标。
|
||||||
|
2. **P2 真实 focus 同步 Tab 入口**:ToggleButton `focus` 调用 `group.noteFocus(key)`,仅更新 `active` 并 bump version,不重复 `focus()`。鼠标/`HTMLElement.focus()` 进入非入口成员后,该成员变为唯一 `tabindex=0`。正式回归 `real focus moves the single Tab entry to that member`。
|
||||||
|
|
||||||
|
RTL 回归改为**三个成员**,可区分正向与反向;重排测试使用稳定 VNode `:key`。
|
||||||
|
|
||||||
|
### 最终命令结果
|
||||||
|
|
||||||
|
| 命令 | 结果 |
|
||||||
|
| -------------------------------------- | ----------------------------------- |
|
||||||
|
| `pnpm test` | 26 文件 / **449** 通过(含 SSR 14) |
|
||||||
|
| `pnpm test:unit` | 25 文件 / **435** 通过 |
|
||||||
|
| `pnpm test:ssr` | 14 通过 |
|
||||||
|
| `pnpm typecheck` | 通过 |
|
||||||
|
| `pnpm build:docs` / `build:playground` | 通过 |
|
||||||
|
| `pnpm format` / `git diff --check` | 通过 |
|
||||||
|
|
||||||
|
拆分:`tests/button-toggle.test.ts` **40** + `tests/m26-review.probe.test.ts` **12** = **52**(此前报告写 48 且与 39+10 明细不一致,已更正)。
|
||||||
|
|
||||||
|
### 浏览器
|
||||||
|
|
||||||
|
- 5173:每组仍为单 Tab 入口(1×`tabindex=0`,其余 `-1`)。
|
||||||
|
- IAB 无法稳定派发键盘/指针;重排导航与鼠标聚焦后返回以单元回归为准,未做真实浏览器重复验收。
|
||||||
|
|
||||||
|
### 口径更正
|
||||||
|
|
||||||
|
- SSR 测试是 `renderToString` 字符串断言,**不是**实际水合验收。
|
||||||
|
- 源码 `typecheck` 与 dist 声明抽查 **不等于** 打包产物独立安装消费通过。
|
||||||
|
- 未完成项不变:逐像素、读屏、Nuxt 水合、独立安装、真实 RTL 浏览器操作。
|
||||||
|
|
||||||
|
## 集成人最终复核(2026-10-23)
|
||||||
|
|
||||||
|
本批复核通过,可以提交。上两次报告保留为历史问题记录;12 项独立复核回归全部通过,实时 DOM 导航及真实 focus 同步均已核对。
|
||||||
|
|
||||||
|
集成人重新执行:全量 26 文件/449 项(含 SSR 14)、类型检查、文档及 playground 生产构建、格式与 diff 检查均通过。文档构建仍有大于 500 kB 的 chunk 提示,不影响构建成功;不因此声明完成体积优化。
|
||||||
|
|
||||||
|
5173 浏览器重点验证:从 basic 组 Italic 按 Right 聚焦 Underline,Tab 退出到示例代码展开按钮,再 Shift+Tab 返回 Underline。带 key 重排、事件取消、RTL 等由自动回归覆盖,本轮未在浏览器逐项重复。集成人同时纠正文档:子项 false 不能解除 ToggleButtonGroup 整体禁用,disallowEmptySelection 不自动建立初始选择。
|
||||||
|
|
||||||
|
完整读屏、触屏、逐像素、Nuxt 水合和打包后独立安装仍未验收。下一批任务见 [M29 Toolbar 提示词](./M29-toolbar-prompt.md)。
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# 交给实现 AI 的下一阶段提示词
|
||||||
|
|
||||||
|
请先返修 M26–M28(ButtonGroup / ToggleButton / ToggleButtonGroup),暂不开始 Toolbar。当前独立复核未通过,尚未提交。
|
||||||
|
|
||||||
|
工作目录是独立 Git 仓库 heroui-vue。先读取根 AGENTS.md、适用迁移约定、docs/migrations/M26-M28-review.md 和 tests/m26-review.probe.test.ts,以固定 HeroUI 提交为基线。不要修改相邻 React 参考仓库。
|
||||||
|
|
||||||
|
逐项修复复核报告的七类问题:
|
||||||
|
|
||||||
|
1. 点击、键盘取消事件必须阻止内部选择或焦点更新,覆盖独立与组内 ToggleButton、受支持的 asChild 及事件合并顺序。
|
||||||
|
2. 动态 multiple/single 切换必须协调内部选择状态和公开值形态,保证单选最多一个选中;受控父级拒绝更新时不得自行覆盖外部值。
|
||||||
|
3. 修复焦点注册的响应性、动态 key、DOM 重排、移除/禁用当前项和 Tab/Shift+Tab。优先评估 Reka 独立 RovingFocus 能力;选择符合上游体验的导航策略并验证,不新增第二套全局键盘协议。
|
||||||
|
4. 分离组内逻辑 key 与 DOM id,保留数字/字符串键的区别,避免跨组重复 ID,验证 SSR/水合稳定性。
|
||||||
|
5. 组 size 等继承上下文必须响应式,显式子项属性优先,取消覆盖后恢复继承。
|
||||||
|
6. 方向键遵循 orientation 和 RTL,并尊重调用方取消;不处理无关轴方向键。
|
||||||
|
7. ButtonGroup 默认禁用遵循上游直接属性优先级,同时保留 Fieldset 与原生禁用约束,不破坏已有 Button 行为。
|
||||||
|
|
||||||
|
保留复核探针,修复行为后整理合并进正式测试并加入 test:unit。禁止通过删除、skip、削弱断言或只改报告来关闭问题。单选组方向键只移动焦点、Enter/Space 切换选择即可,不要额外改成方向键自动选择。
|
||||||
|
|
||||||
|
补齐全部 26 个演示的编译/挂载与 Vue 警告检查,发布类型正反例,以及打包产物的独立消费验证。浏览器集中验证键盘入口/退出、两种方向与 RTL、动态成员变化及取消事件,不必逐页点击。保持组件/文档/主题与固定上游一致,文档展示和复制代码共用 SFC,图标使用 Tabler Vue,API 表格全宽且内容换行。
|
||||||
|
|
||||||
|
不要无关重构字段/弹层基础设施,不覆盖其他人的改动,不删除已有截图。若必须修改共享协议,先在报告说明具体原因与影响。
|
||||||
|
|
||||||
|
执行现有可用命令:pnpm test、pnpm test:unit、pnpm test:ssr、pnpm typecheck、pnpm build、pnpm build:docs、pnpm build:playground、pnpm format,并执行 git diff --check。实际浏览器、SSR 水合及独立消费验证如没有自动脚本,应给出可复现步骤与真实结果,不把未执行项写为通过。
|
||||||
|
|
||||||
|
更新 docs/migrations/M26-M28-button-toggle.md、兼容矩阵和验证记录,纠正原本批测试数 32 的错误(返修前实际为 31)。报告七项修复、回归覆盖、命令结果及仍存在的差异。完成后先交回复核,不自行提交,也不开始 Toolbar。
|
||||||
|
|
||||||
|
这批通过并提交后,下一组件为 Toolbar,届时再根据已验收的按钮组/焦点能力安排具体迁移任务。
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# M26–M28 第二次复核(2026-10-23)
|
||||||
|
|
||||||
|
结论:暂未通过,不提交。上轮原有 10 项探针全部通过,但焦点协议仍有两个缺口。下一任务先完成下面两项返修,Toolbar 待本批验收后开始。
|
||||||
|
|
||||||
|
## 本轮验证
|
||||||
|
|
||||||
|
- 返修版本 `pnpm test`:26 文件、446 项通过,其中 SSR 14 项;`pnpm typecheck` 通过。
|
||||||
|
- 随后新增两项更严格的回归,运行 `pnpm exec vitest run tests/m26-review.probe.test.ts`:12 项中 10 项通过、2 项失败。当前工作区全量测试已包含失败项,不能沿用 446 项通过作为最终验收结论。
|
||||||
|
- 没有重复运行生产构建或浏览器。问题由真实 DOM focus 与带 key 的 Vue 更新复现,不依赖 jsdom 的布局测量。
|
||||||
|
|
||||||
|
## 1. P1:有 key 的 DOM 重排后,方向键仍按初次注册顺序导航
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/toggle-button-group/useToggleButtonSelection.ts` 的 `ordered()`。
|
||||||
|
|
||||||
|
复现:使用 `v-for` 和稳定 `:key` 渲染 a/b/c,改为 c/b/a,聚焦 b,按 ArrowRight。预期聚焦右边的 a,实际聚焦左边的 c。当前 `ordered()` 只读取 Map 插入顺序,Vue 复用并移动已有实例时不会重新注册。
|
||||||
|
|
||||||
|
原有“reordering members”测试没有给成员设置 VNode key,也没有断言重排后的方向键目标,只检查焦点和 Tab stop 数量,因此不能证明此能力已修复。必须按当前 DOM/可靠集合顺序导航;嵌套组应隔离,禁用项应跳过。补测带 key 重排、Home/End、RTL/垂直及动态插入,不得通过强制重建所有子项规避正常 Vue 更新。
|
||||||
|
|
||||||
|
新增失败测试:`arrow navigation follows keyed DOM order after a reorder`。
|
||||||
|
|
||||||
|
## 2. P2:直接聚焦成员后,单 Tab 入口仍停留在旧成员
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/toggle-button/ToggleButton.vue` 的 `focus()`,及 `useToggleRovingFocus()` 的 active 同步。
|
||||||
|
|
||||||
|
复现:三个成员初始 a 为 Tab 入口,通过真实 HTMLElement.focus() 聚焦 c,等待 Vue 更新。c 仍为 tabindex=-1,a 仍为 0。当前 active 只在内部方向键和注册时更新,focus 处理仅更新视觉状态。鼠标或调用方 focus 进入非入口成员后,离开再返回无法恢复到实际活动成员。
|
||||||
|
|
||||||
|
既然本批选择单 Tab 入口策略,就应让真实聚焦的可用成员同步为入口。只同步 active,不要重新调用 focus 形成递归,也不要仅在 click 中更新;验证焦点路径、禁用、卸载和嵌套组。
|
||||||
|
|
||||||
|
新增失败测试:`focusing a member updates the single Tab entry to that member`。
|
||||||
|
|
||||||
|
## 实现者下一步提示词
|
||||||
|
|
||||||
|
继续返修 M26–M28,暂不迁移 Toolbar,也不要提交。先读取 AGENTS.md、本报告与上一轮复核报告。保留 `tests/m26-review.probe.test.ts` 的全部 12 项断言,修复上面两个焦点缺口,并将相关用例整理为正式回归。
|
||||||
|
|
||||||
|
优先复用可靠的集合/焦点能力;若保留现有实现,按实际 DOM 顺序导航并同步真实 focus,不增加 document 全局监听或额外选择状态。不要以数组重建、删除 VNode key、放宽断言或单纯调整报告关闭问题。
|
||||||
|
|
||||||
|
改进现有重排测试:使用稳定 VNode key,断言重排后的具体方向键目标;RTL 用至少三个成员验证,两个成员的循环不能区分正向与反向。重点浏览器验证一次键盘进入/退出、重排导航与鼠标聚焦后返回,无需逐页点击。
|
||||||
|
|
||||||
|
通过后运行 pnpm test、pnpm test:unit、pnpm test:ssr、pnpm typecheck、pnpm build:docs、pnpm build:playground、pnpm format 和 git diff --check,更新迁移/验证报告的实际最终计数。当前报告“返修后 48 项”与其明细 39+10 不一致,也一并修正。SSR 字符串检查不能写成实际水合通过,源码类型检查和 dist 抽查不能写成打包独立消费通过。未完成的验收继续如实记录。
|
||||||
|
|
||||||
|
完成后交回复核。本批通过并提交后,下阶段为 Toolbar,再提供该阶段完整任务范围。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 实现者返修记录(2026-10-23)
|
||||||
|
|
||||||
|
探针 `tests/m26-review.probe.test.ts`:**12/12 通过**。
|
||||||
|
|
||||||
|
| 问题 | 处理 |
|
||||||
|
| ------------------- | -------------------------------------------------------- |
|
||||||
|
| P1 keyed DOM 重排 | `ordered()` 按 `compareDocumentPosition` 实时 DOM 序导航 |
|
||||||
|
| P2 focus → Tab 入口 | `noteFocus` 同步 active,不递归 focus |
|
||||||
|
|
||||||
|
正式回归已加强:稳定 `:key` 重排断言具体方向键目标;RTL 三成员;真实 focus 更新唯一 tabstop。
|
||||||
|
|
||||||
|
最终:`pnpm test` 26/449(SSR 14);`test:unit` 25/435(button-toggle 40 + probe 12)。typecheck / build:docs / build:playground / format / git diff --check 通过。待复核,不提交。
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
# M26–M28 独立复核(2026-10-23)
|
||||||
|
|
||||||
|
结论:暂未通过,不提交。本轮检查 ButtonGroup、ToggleButton、ToggleButtonGroup 的代码、固定上游契约及回归测试。下一阶段先返修本批,通过复核后再迁移 Toolbar。
|
||||||
|
|
||||||
|
## 验证证据
|
||||||
|
|
||||||
|
- 原有 `pnpm test`:25 个文件、426 项通过,其中 SSR 12 项;`pnpm typecheck` 通过。
|
||||||
|
- 原有 `tests/button-toggle.test.ts` 实际 31 项,迁移报告写为 32 项,应纠正。
|
||||||
|
- 新增 `tests/m26-review.probe.test.ts`:10 项中 9 项失败、1 项通过。它们复现了原测试遗漏的行为;当前包含探针的全量测试不能称为通过。
|
||||||
|
- 本轮没有重新执行生产构建或浏览器验收;不能将实现者的执行记录写成复核者已验证的结果。没有进行逐像素验收。
|
||||||
|
|
||||||
|
## 必修问题
|
||||||
|
|
||||||
|
### 1. P1:调用方取消事件后仍切换状态或移动焦点
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/toggle-button/ToggleButton.vue:80`、`packages/vue/src/components/toggle-button-group/useToggleButtonSelection.ts:135`。
|
||||||
|
|
||||||
|
独立按钮与组内按钮设置 `@click.prevent`,仍触发选择变更;设置 `@keydown.prevent` 后,ArrowRight 仍移动焦点。内部处理没有尊重 `defaultPrevented`。修复事件合并和执行顺序,覆盖独立、组内及 asChild 支持场景,避免重复回调。探针有两项失败。
|
||||||
|
|
||||||
|
### 2. P1:多选动态改为单选后仍有两个已选 radio
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/toggle-button-group/useToggleButtonSelection.ts:61`。
|
||||||
|
|
||||||
|
非受控组以 multiple 和 `[a, b]` 初始化,再切换为 single,两个子项均为 `role=radio aria-checked=true`。当前只规范化外部值,直接返回原内部数组。需要协调模式切换后的内部状态和公开值形态,覆盖受控父级拒绝更新、禁止空选与数组不可变性。
|
||||||
|
|
||||||
|
### 3. P1:焦点注册与 Tab 行为不完整
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/toggle-button-group/useToggleButtonSelection.ts:104`、`packages/vue/src/components/toggle-button/ToggleButton.vue:123`。
|
||||||
|
|
||||||
|
初始三个可用成员都保留 `tabindex=0`,同时没有实现上游 toolbar 的 Tab 跳过组内剩余成员的策略。`shallowRef(Map)` 原地修改不能通知成员重新计算。成员仅在 mounted 注册,同一实例的 value 从 a 改为 c 后,方向键查询不到新 key,焦点停住。探针分别复现这两点。
|
||||||
|
|
||||||
|
注册顺序还直接作为导航顺序,需补测 DOM 重排、移除当前项、动态禁用、Tab/Shift+Tab。可以采用可靠的单 Tab 入口策略,或保留上游 toolbar 的 Tab 跳转策略,不能两者都不实现。评估独立使用 Reka RovingFocus 能力,不能因为 ToggleGroup 的 role 限制就默认自行实现全部焦点规则。
|
||||||
|
|
||||||
|
单选组方向键只移动焦点、Enter/Space 切换选择是可接受的上游行为,不要求方向键自动修改选择。
|
||||||
|
|
||||||
|
### 4. P2:逻辑选择 key 泄漏为重复 DOM id
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/toggle-button/ToggleButton.vue:153`。
|
||||||
|
|
||||||
|
组内数字 `1` 和字符串 `"1"` 是不同逻辑 key,却生成两个 `id="1"`;不同组重用相同 key 也会冲突。上游交互适配将组内 id 用于逻辑键,不直接作为 DOM id。应分离逻辑 key 与 DOM id,需要真实 DOM id 时保证唯一且 SSR 稳定;保留独立按钮的 id 语义。探针允许移除不必要的 DOM id 或生成唯一 id,不限定具体修复方式。
|
||||||
|
|
||||||
|
### 5. P2:组尺寸继承不是响应式
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/toggle-button-group/ToggleButtonGroup.vue:145`、`packages/vue/src/components/toggle-button/ToggleButton.vue:144`。
|
||||||
|
|
||||||
|
上下文保存 setup 时的 `props.size` 快照。组从 sm 切换 lg,已有按钮仍使用 sm。使用响应式上下文,并验证子项显式覆盖及取消覆盖后恢复继承。
|
||||||
|
|
||||||
|
### 6. P2:键盘导航忽略 orientation 与 RTL
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/toggle-button-group/useToggleButtonSelection.ts:140`。
|
||||||
|
|
||||||
|
当前同时接受两轴方向键,且硬编码后丢弃 horizontal。vertical 组的 ArrowRight 也移动焦点,水平 RTL 没有反转。需按方向和 locale/dir 处理,保留垂直组的左右键等无关事件。探针复现垂直组错误;RTL 还需补回归。
|
||||||
|
|
||||||
|
### 7. P2:ButtonGroup 禁用默认值不能被子项显式 false 覆盖
|
||||||
|
|
||||||
|
位置:`packages/vue/src/components/button/Button.vue:51`。
|
||||||
|
|
||||||
|
`<ButtonGroup is-disabled>` 中显式 `:is-disabled="false"` 的 Button 仍禁用。固定上游 `packages/react/src/components/button/button.tsx` 使用空值优先级,直接属性优先于组上下文;当前 OR 合并不符合该契约。区分省略与显式 false,修复组默认值合并,同时保留 Fieldset 等原生/字段强制禁用语义。
|
||||||
|
|
||||||
|
## 验收补充
|
||||||
|
|
||||||
|
- 保留失败探针,将其整理进正式回归测试并纳入 `test:unit`,不能删除、跳过或放宽断言来取得绿色结果。
|
||||||
|
- 26 个演示需要真实编译/挂载并检查 Vue 警告;仅检查文件名和包含 template 不等于演示可运行。
|
||||||
|
- 修复后重点浏览器验证 Tab/Shift+Tab、方向/RTL、动态成员变化与事件取消即可,无需逐页点击全部文档。
|
||||||
|
- 补齐 SSR/水合 ID 验证、发布声明正反例和打包产物独立消费;按实际执行记录结果,明确未完成项。
|
||||||
|
|
||||||
|
## 参考边界
|
||||||
|
|
||||||
|
首要基线为本地 HeroUI 固定提交 `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`。另核对 Adobe 官方当前 [useToggleButtonGroup 源码](https://github.com/adobe/react-spectrum/blob/main/packages/react-aria/src/button/useToggleButtonGroup.ts) 与 [useToolbar 源码](https://github.com/adobe/react-spectrum/blob/main/packages/react-aria/src/toolbar/useToolbar.ts),辅助确认组语义、DOM id 处理、方向及 Tab 策略;这不是固定依赖版本的运行验收。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 实现者返修记录(2026-10-23)
|
||||||
|
|
||||||
|
探针 `tests/m26-review.probe.test.ts`:**10/10 通过**(原 9 失败)。断言未删改,已纳入 `test:unit`。
|
||||||
|
|
||||||
|
| 问题 | 处理 |
|
||||||
|
| ------------------ | ------------------------------------------------------------------ |
|
||||||
|
| P1 事件取消 | `defaultPrevented` 短路 `request`/`keydown` |
|
||||||
|
| P1 multiple→single | 非受控折叠为单 key;受控不覆盖外部值 |
|
||||||
|
| P1 焦点/Tab | version 响应式注册、动态 key 重绑、单 Tab 入口、禁用项让出 tabstop |
|
||||||
|
| P2 DOM id | 组内逻辑 key 不写 DOM id;独立按钮保留 id |
|
||||||
|
| P2 size 继承 | 上下文 computed;覆盖/恢复有回归 |
|
||||||
|
| P2 orientation/RTL | 水平含 RTL 反转,垂直仅上下键,无关轴不拦截 |
|
||||||
|
| P2 Button 禁用 | `??` 空值优先级 + Fieldset 强制禁用保留 |
|
||||||
|
|
||||||
|
全量:`pnpm test` 26 文件 / 446(SSR 14);`test:unit` 25 / 432。26 演示真实挂载无 Vue warning。详见 [M26–M28 报告](./M26-M28-button-toggle.md)。待复核,不提交。
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
# M29 Toolbar:交给实现 AI 的提示词
|
||||||
|
|
||||||
|
请继续迁移 Toolbar。前置 M26–M28 ButtonGroup / ToggleButton / ToggleButtonGroup 已由集成人复核通过;本轮只完成 Toolbar 及其必要的局部组合适配,不迁移菜单、Select、日期或其他家族,不自行提交。
|
||||||
|
|
||||||
|
## 先读与基线
|
||||||
|
|
||||||
|
工作仓库为独立 heroui-vue,先读 AGENTS.md、docs/migration-handoff.md、docs/migrations/M13-M20-lessons.md,以及 M26–M28 两次复核报告与最终验收记录。保持相邻 React 参考仓库只读。固定 HeroUI 3.2.6 提交 `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`,不要按最新官网更换基线。
|
||||||
|
|
||||||
|
参考目录(相对 Vue 仓库):
|
||||||
|
|
||||||
|
- `../heroui/packages/react/src/components/toolbar/`:实现、导出、stories。
|
||||||
|
- `../heroui/packages/styles/components/toolbar.css` 和 `../heroui/packages/styles/src/components/toolbar/`。
|
||||||
|
- `../heroui/apps/docs/content/docs/cn/react/components/(layout)/toolbar.mdx`。
|
||||||
|
- `../heroui/apps/docs/src/demos/cn/toolbar/`:5 个完整示例。
|
||||||
|
|
||||||
|
先列出公共 API、状态/键盘语义、继承关系和全部示例,再核验当前安装版 Reka Toolbar 的真实导出、组合要求及可用能力。不要因为名字相同就假定能无缝替换。
|
||||||
|
|
||||||
|
## 实现范围
|
||||||
|
|
||||||
|
导出 Toolbar(如约定需要则同时导出 ToolbarRoot)、ToolbarProps/变体类型、toolbarVariants;提供独立 CSS、中文组件页、导航及 5 个实际 SFC 示例,顺序为 basic、vertical、attached、with-button-group、custom-styles。文案、布局、间距、圆角、主题、阴影和 Tailwind 定制示例与固定上游一致;图标用现有 Tabler Vue,不自绘。
|
||||||
|
|
||||||
|
保留 `isAttached`(默认 false)、`orientation`(默认 horizontal)、aria-label/aria-labelledby、class/style/DOM 事件及作用域插槽 orientation。React children/render prop 转为 Vue 插槽并记录差异,不引入 React 类型或新的状态库。
|
||||||
|
|
||||||
|
基线 Toolbar 向 ToggleButtonGroup 提供缺省 orientation,并向 Separator 提供与工具栏垂直的方向;子项显式 orientation 优先,取消覆盖后恢复继承。核对 ButtonGroup 的基线方向与视觉,不凭推测给所有后代强制同一方向。上下文动态更新、嵌套 Toolbar 和组边界必须正确。
|
||||||
|
|
||||||
|
## 最重要的组合边界
|
||||||
|
|
||||||
|
优先用 Reka Toolbar/独立焦点能力实现真实工具栏导航。ButtonGroup、ToggleButtonGroup 已有上下文与焦点处理,不允许父 Toolbar 和子组对同一次方向键各自执行一次导航。先确定嵌套组的焦点所有权、Tab 入口/退出与跨组导航策略,并与上游契约对照。不得交付只能在某一小组内部移动、无法遍历工具栏其余按钮的演示。
|
||||||
|
|
||||||
|
只做 Toolbar 所需的最小局部适配。允许新增私有 toolbar 上下文,并对 Separator、ButtonGroup、ToggleButtonGroup/ToggleButton 做必要接入,但先在报告列出具体缺口、方案和影响,保留其独立使用行为与已有回归。不要重构 field/choice、表单、弹层、ConfigProvider 或建立第二套全局 document 键盘/关闭/焦点队列;需要跨这些内核改协议时,先交具体失败场景给集成人。
|
||||||
|
|
||||||
|
## 必须覆盖的回归
|
||||||
|
|
||||||
|
- 真实 role、可访问名称、方向、attached 变体、attrs 动态增删及 class/style 合并。
|
||||||
|
- 水平/垂直、LTR/RTL(至少三个成员,不能用两个循环项证明反转)、禁用项跳过、Tab/Shift+Tab、边界导航和嵌套工具栏隔离;Home/End/循环行为按实际目标契约确定并记录。
|
||||||
|
- 与 Button、ButtonGroup、ToggleButtonGroup、Separator 的组合。一次按键只移动一次,Enter/Space 不重复激活,调用方 preventDefault/capture/处理器数组按既有事件约定生效,选择状态不被工具栏焦点请求意外改变。
|
||||||
|
- 使用稳定 VNode key 测试增删重排,断言移动后的具体焦点目标;不要只断言 Tab stop 数量。鼠标/调用方 focus 后,活动入口与焦点同步;禁用、移除当前项和全部禁用后启用也要验证。
|
||||||
|
- 方向继承的动态修改、显式覆盖及恢复;Separator 的 DOM/ARIA 与实际视觉方向保持一致。
|
||||||
|
- SSR 不访问浏览器全局;实际水合另设回归,不把 renderToString 冒烟写成水合通过。
|
||||||
|
- 5 个演示真实导入编译/挂载且无 Vue warning。公共类型有合法/非法断言,并检查构建后的声明。
|
||||||
|
|
||||||
|
浏览器只重点验证组合工具栏的跨组方向导航、Tab 退出与返回、垂直模式和焦点环,无需逐页点全部示例。文档代码预览、复制和高亮共用同一 SFC;API/插槽等长短表统一全宽、自动换行且无横向溢出。
|
||||||
|
|
||||||
|
## 交付
|
||||||
|
|
||||||
|
执行 pnpm test、pnpm test:unit、pnpm test:ssr、pnpm typecheck、pnpm build:docs、pnpm build:playground、pnpm format 与 git diff --check,记录各入口实际结果。新增测试接入 test:unit。同步 compatibility.md、upstream.md、verification.md,新增 M29-toolbar.md:列 API/示例对照、底座取舍、共享文件修改、键盘所有权、差异和验证边界。
|
||||||
|
|
||||||
|
当前 M26–M28 的验收基线为 26 文件/449 项全量测试(含 SSR 14)、单元 435 项。本轮新增后按实际计数更新;不要沿用旧数字,也不要将源码类型检查、dist 抽查描述成独立打包安装已通过。完整读屏/触屏、自动逐像素、Nuxt、独立安装等未执行项如实保留。
|
||||||
|
|
||||||
|
完成后交回复核,不自行提交、不接着开始下一家族。
|
||||||
+10
-1
@@ -3,7 +3,7 @@
|
|||||||
- 项目:https://github.com/heroui-inc/heroui
|
- 项目:https://github.com/heroui-inc/heroui
|
||||||
- 基线版本:3.2.6
|
- 基线版本:3.2.6
|
||||||
- 提交:ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960
|
- 提交:ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960
|
||||||
- 本次更新:2026-10-22
|
- 本次更新:2026-10-24
|
||||||
|
|
||||||
## 已移植
|
## 已移植
|
||||||
|
|
||||||
@@ -26,6 +26,15 @@
|
|||||||
|
|
||||||
构建与运行不依赖相邻 React 仓库。完整源样式移植记录以本文件及源码顶部声明为准。
|
构建与运行不依赖相邻 React 仓库。完整源样式移植记录以本文件及源码顶部声明为准。
|
||||||
|
|
||||||
|
## M26–M28 ButtonGroup / ToggleButton / ToggleButtonGroup
|
||||||
|
|
||||||
|
- packages/styles/components/{button-group,toggle-button,toggle-button-group}.css:移植基线 CSS,类名加 hv- 前缀;`.button`/`.button--outline` 映射为 `.hv-button`/`.hv-button--outline`。
|
||||||
|
- packages/styles/src/index.ts:buttonGroupVariants、toggleButtonVariants、toggleButtonGroupVariants,保留基线 slot/variant 集合与 hv- 命名空间。
|
||||||
|
- packages/react/src/components/{button-group,toggle-button,toggle-button-group}/*.tsx 与 stories:公共 API、直接子级继承、Separator 置于按钮内容内、selectionMode/disallowEmptySelection 语义。
|
||||||
|
- apps/docs/content/docs/cn/react/components/(buttons)/{button-group,toggle-button,toggle-button-group}.mdx:中文标题、说明、示例顺序、API 表格与样式参考。
|
||||||
|
- docs 引用的 26 个 ComponentPreview 示例由新项目 SFC 实现;图标改用 Tabler 官方 Vue 组件(原 gravity-ui:heart 等)。
|
||||||
|
- React Aria ToggleButtonGroup 的 toolbar/radiogroup 语义由 Vue 自实现选择内核对齐;Reka ToggleGroup 固定 role=group 且无 disallowEmptySelection,故未直接采用。
|
||||||
|
|
||||||
## 本批文档适配
|
## 本批文档适配
|
||||||
|
|
||||||
- Card 的头像改用本库 Avatar/AvatarImage/AvatarFallback(内部为 Reka Avatar);图片沿用上游 CDN URL,不复制媒体文件。关闭按钮改用本库 CloseButton(默认基线 CloseIcon)。
|
- Card 的头像改用本库 Avatar/AvatarImage/AvatarFallback(内部为 Reka Avatar);图片沿用上游 CDN URL,不复制媒体文件。关闭按钮改用本库 CloseButton(默认基线 CloseIcon)。
|
||||||
|
|||||||
@@ -478,3 +478,38 @@ typecheck、build:docs、build:playground、format、diff-check 通过;文档
|
|||||||
| pnpm test:unit | 23 | 383 | 不含 node SSR |
|
| pnpm test:unit | 23 | 383 | 不含 node SSR |
|
||||||
|
|
||||||
typecheck、build:docs、build:playground、format、diff-check 与 dist 正反类型消费通过。浏览器重点验证横向末端/RTL/垂直溢出、动态增减内容、禁用跳过、指示器和文档表格。未声明完整读屏/触屏、自动逐像素、Nuxt 或打包后独立安装。
|
typecheck、build:docs、build:playground、format、diff-check 与 dist 正反类型消费通过。浏览器重点验证横向末端/RTL/垂直溢出、动态增减内容、禁用跳过、指示器和文档表格。未声明完整读屏/触屏、自动逐像素、Nuxt 或打包后独立安装。
|
||||||
|
|
||||||
|
## M26–M28 ButtonGroup / ToggleButton / ToggleButtonGroup(首次记录,2026-10-23)
|
||||||
|
|
||||||
|
- 9 + 7 + 10 个固定基线预览已迁移,顺序与中文文档一致;预览、复制、高亮共用同一 SFC。
|
||||||
|
- Button 仅扩展直接子级组上下文合并,未改写共享按钮事件内核;字段/choice 协议未改动。
|
||||||
|
- ToggleButtonGroup 自实现选择与 roving focus,以对齐 toolbar/radiogroup 与 disallowEmptySelection;未引入新依赖。
|
||||||
|
- 返修后:`pnpm test` 26 文件 / 446 通过(含 node SSR 14);`pnpm test:unit` 25 文件 / 432 通过(含复核探针 10);typecheck / build:docs / build:playground / format / git diff --check 通过。
|
||||||
|
- 公共类型合法/非法用例见 tests/types/button-toggle-contract.ts;dist 声明已抽查可解析。
|
||||||
|
- 浏览器 5173 DOM 快照抽查三页结构与 ARIA(toolbar/pressed/disabled);首次 IAB 截图与指针点击未完成,返修前本批单元用例实际为 31 项。未宣称逐像素或读屏验收完成。
|
||||||
|
|
||||||
|
详见 [M26–M28 报告](./migrations/M26-M28-button-toggle.md)。
|
||||||
|
|
||||||
|
## M26–M28 返修(2026-10-23)
|
||||||
|
|
||||||
|
- 复核七项问题已修复,探针 10/10;未通过删断言或 skip 取绿。
|
||||||
|
- 26 个演示真实 mount、无 Vue warning;类型正反例与 SSR DOM id 稳定性已覆盖。
|
||||||
|
- 浏览器确认单 Tab 入口与 toolbar/radiogroup 角色;首次返修的 IAB 未稳定派发键盘/指针,交互回归为 39 + 10 = 49 项。
|
||||||
|
- 打包独立消费、读屏、RTL 真实浏览器、逐像素仍未完成。
|
||||||
|
|
||||||
|
详见 [M26–M28 报告](./migrations/M26-M28-button-toggle.md)。
|
||||||
|
|
||||||
|
## M26–M28 第二次返修(2026-10-23)
|
||||||
|
|
||||||
|
- 焦点两缺口已修:DOM 序导航、真实 focus 同步 Tab 入口。探针 12/12。
|
||||||
|
- `pnpm test` 26 文件 / 449;`test:unit` 25 / 435。其余命令通过。
|
||||||
|
- SSR 仅为服务端字符串断言,非水合验收;dist 抽查非独立安装验收。
|
||||||
|
- IAB 未重复完成键盘/鼠标真实操作,相关行为以单元回归为准。
|
||||||
|
|
||||||
|
详见 [M26–M28 报告](./migrations/M26-M28-button-toggle.md) 与 [第二次复核](./migrations/M26-M28-review-2.md)。
|
||||||
|
|
||||||
|
## M26–M28 最终独立复核(2026-10-23)
|
||||||
|
|
||||||
|
集成人复核通过,历史失败记录已由 12 项回归关闭。独立重跑全量测试 26 文件/449 项(SSR 14)、test:unit 25 文件/435 项、test:ssr 14 项,以及 typecheck、build:docs、build:playground、format、diff 检查通过。文档构建有 chunk 大小提示;未做体积优化验收。
|
||||||
|
|
||||||
|
浏览器 5173 basic 组实际键盘:Italic → Right → Underline,Tab 到示例展开按钮,Shift+Tab 返回 Underline。动态带 key 重排、取消事件、方向/RTL 等由自动回归验证;没有在浏览器全部重复。未声明完整水合、读屏、触屏、逐像素或打包独立安装通过。
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||||
"typecheck": "vue-tsc --noEmit",
|
"typecheck": "vue-tsc --noEmit",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts",
|
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts",
|
||||||
"test:ssr": "vitest run tests/ssr.test.ts",
|
"test:ssr": "vitest run tests/ssr.test.ts",
|
||||||
"format": "prettier --check .",
|
"format": "prettier --check .",
|
||||||
"format:fix": "prettier --write .",
|
"format:fix": "prettier --write .",
|
||||||
|
|||||||
@@ -0,0 +1,148 @@
|
|||||||
|
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||||
|
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||||
|
/* ==========================================================================
|
||||||
|
ButtonGroup - Groups related buttons together
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
/* Base button group styles */
|
||||||
|
.hv-button-group {
|
||||||
|
@apply inline-flex h-auto items-center justify-center gap-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Orientation variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-button-group--horizontal {
|
||||||
|
@apply flex-row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-button-group--vertical {
|
||||||
|
@apply flex-col;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove border radius from all buttons in group */
|
||||||
|
.hv-button-group .hv-button {
|
||||||
|
@apply rounded-none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply border radius to first button (start edge) */
|
||||||
|
.hv-button-group--horizontal .hv-button:first-child {
|
||||||
|
@apply rounded-s-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply border radius to last button (end edge) */
|
||||||
|
.hv-button-group--horizontal .hv-button:last-child {
|
||||||
|
@apply rounded-e-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If only one button, apply both rounded edges */
|
||||||
|
.hv-button-group--horizontal .hv-button:first-child:last-child {
|
||||||
|
@apply rounded-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply border radius to first button (top edge) in vertical */
|
||||||
|
.hv-button-group--vertical .hv-button:first-child {
|
||||||
|
@apply rounded-t-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply border radius to last button (bottom edge) in vertical */
|
||||||
|
.hv-button-group--vertical .hv-button:last-child {
|
||||||
|
@apply rounded-b-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If only one button in vertical, apply all rounded edges */
|
||||||
|
.hv-button-group--vertical .hv-button:first-child:last-child {
|
||||||
|
@apply rounded-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove scale transform on active/pressed state for buttons in group */
|
||||||
|
.hv-button-group .hv-button:active,
|
||||||
|
.hv-button-group .hv-button[data-pressed="true"] {
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Raise focused button so its outward focus ring + gap shows above adjacent buttons */
|
||||||
|
.hv-button-group .hv-button:focus-visible:not([data-focused]),
|
||||||
|
.hv-button-group .hv-button[data-focus-visible="true"] {
|
||||||
|
@apply z-10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Separator (compound component)
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-button-group__separator {
|
||||||
|
@apply rounded-sm bg-current opacity-15;
|
||||||
|
position: absolute;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transitions
|
||||||
|
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||||
|
*/
|
||||||
|
transition: opacity 150ms var(--ease-smooth);
|
||||||
|
@apply motion-reduce:transition-none;
|
||||||
|
|
||||||
|
/* Horizontal orientation - vertical divider */
|
||||||
|
.hv-button-group--horizontal & {
|
||||||
|
inset-inline-start: -1px;
|
||||||
|
top: 25%;
|
||||||
|
width: 1px;
|
||||||
|
height: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Vertical orientation - horizontal divider */
|
||||||
|
.hv-button-group--vertical & {
|
||||||
|
inset-inline-start: 25%;
|
||||||
|
top: -1px;
|
||||||
|
width: 50%;
|
||||||
|
height: 1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Outline button border handling
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
/* Remove adjacent borders from outline buttons in horizontal group */
|
||||||
|
/* First button: remove end border (right in LTR, left in RTL) */
|
||||||
|
.hv-button-group--horizontal .hv-button--outline:first-child {
|
||||||
|
@apply border-e-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Last button: remove start border (left in LTR, right in RTL) */
|
||||||
|
.hv-button-group--horizontal .hv-button--outline:last-child {
|
||||||
|
@apply border-s-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Middle buttons: remove both inline borders */
|
||||||
|
.hv-button-group--horizontal
|
||||||
|
.hv-button--outline:not(:first-child):not(:last-child) {
|
||||||
|
@apply border-x-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove adjacent borders from outline buttons in vertical group */
|
||||||
|
/* First button: remove bottom border */
|
||||||
|
.hv-button-group--vertical .hv-button--outline:first-child {
|
||||||
|
@apply border-b-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Last button: remove top border */
|
||||||
|
.hv-button-group--vertical .hv-button--outline:last-child {
|
||||||
|
@apply border-t-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Middle buttons: remove both block borders */
|
||||||
|
.hv-button-group--vertical
|
||||||
|
.hv-button--outline:not(:first-child):not(:last-child) {
|
||||||
|
@apply border-y-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Full width modifier
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-button-group--full-width {
|
||||||
|
@apply w-full;
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||||
|
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||||
|
/* ==========================================================================
|
||||||
|
ToggleButtonGroup - Groups multiple ToggleButtons into a unified control
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
/* Base styles */
|
||||||
|
.hv-toggle-button-group {
|
||||||
|
@apply inline-flex h-auto w-fit items-center justify-center gap-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Orientation variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-toggle-button-group--horizontal {
|
||||||
|
@apply flex-row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button-group--vertical {
|
||||||
|
@apply flex-col;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Full width modifier
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-toggle-button-group--full-width {
|
||||||
|
@apply w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Attached mode (default) - buttons connected with dividers
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
/* Remove border radius from all toggle buttons in attached group */
|
||||||
|
.hv-toggle-button-group .hv-toggle-button {
|
||||||
|
@apply rounded-none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply border radius to first button (start edge) */
|
||||||
|
.hv-toggle-button-group--horizontal .hv-toggle-button:first-child {
|
||||||
|
@apply rounded-s-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply border radius to last button (end edge) */
|
||||||
|
.hv-toggle-button-group--horizontal .hv-toggle-button:last-child {
|
||||||
|
@apply rounded-e-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If only one button, apply both rounded edges */
|
||||||
|
.hv-toggle-button-group--horizontal .hv-toggle-button:first-child:last-child {
|
||||||
|
@apply rounded-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply border radius to first button (top edge) in vertical */
|
||||||
|
.hv-toggle-button-group--vertical .hv-toggle-button:first-child {
|
||||||
|
@apply rounded-t-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply border radius to last button (bottom edge) in vertical */
|
||||||
|
.hv-toggle-button-group--vertical .hv-toggle-button:last-child {
|
||||||
|
@apply rounded-b-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If only one button in vertical, apply all rounded edges */
|
||||||
|
.hv-toggle-button-group--vertical .hv-toggle-button:first-child:last-child {
|
||||||
|
@apply rounded-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove scale transform on active/pressed state for buttons in group */
|
||||||
|
.hv-toggle-button-group .hv-toggle-button:active,
|
||||||
|
.hv-toggle-button-group .hv-toggle-button[data-pressed="true"] {
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Override focus ring to use inset style so it stays within button bounds */
|
||||||
|
.hv-toggle-button-group .hv-toggle-button:focus-visible:not([data-focused]),
|
||||||
|
.hv-toggle-button-group .hv-toggle-button[data-focus-visible="true"] {
|
||||||
|
--tw-ring-offset-width: 0px;
|
||||||
|
@apply ring-inset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Full width: stretch each toggle button */
|
||||||
|
.hv-toggle-button-group--full-width .hv-toggle-button {
|
||||||
|
@apply flex-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Separator (compound component)
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-toggle-button-group__separator {
|
||||||
|
@apply rounded-sm bg-current opacity-15;
|
||||||
|
position: absolute;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transitions
|
||||||
|
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||||
|
*/
|
||||||
|
transition: opacity 150ms var(--ease-smooth);
|
||||||
|
@apply motion-reduce:transition-none;
|
||||||
|
|
||||||
|
/* Horizontal orientation - vertical divider */
|
||||||
|
.hv-toggle-button-group--horizontal & {
|
||||||
|
inset-inline-start: -1px;
|
||||||
|
top: 25%;
|
||||||
|
width: 1px;
|
||||||
|
height: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Vertical orientation - horizontal divider */
|
||||||
|
.hv-toggle-button-group--vertical & {
|
||||||
|
inset-inline-start: 25%;
|
||||||
|
top: -1px;
|
||||||
|
width: 50%;
|
||||||
|
height: 1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Detached mode - buttons separated with gaps
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-toggle-button-group--detached {
|
||||||
|
@apply gap-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Restore border radius in detached mode */
|
||||||
|
.hv-toggle-button-group--detached .hv-toggle-button {
|
||||||
|
@apply rounded-3xl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hide separators in detached mode */
|
||||||
|
.hv-toggle-button-group--detached .hv-toggle-button-group__separator {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||||
|
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||||
|
/* ==========================================================================
|
||||||
|
ToggleButton - Interactive toggle control for on/off states
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
/* Base styles */
|
||||||
|
.hv-toggle-button {
|
||||||
|
@apply relative isolate inline-flex h-10 w-fit origin-center items-center justify-center gap-2 rounded-3xl px-4 text-sm font-medium whitespace-nowrap outline-none select-none no-highlight md:h-9;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transitions
|
||||||
|
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||||
|
*/
|
||||||
|
transition:
|
||||||
|
transform 250ms var(--ease-smooth),
|
||||||
|
background-color 100ms var(--ease-out),
|
||||||
|
box-shadow 100ms var(--ease-out);
|
||||||
|
@apply transform-gpu motion-reduce:transition-none;
|
||||||
|
|
||||||
|
/* Cursor */
|
||||||
|
cursor: var(--cursor-interactive);
|
||||||
|
|
||||||
|
/* Default tokens (unselected state) */
|
||||||
|
--toggle-button-bg: var(--default);
|
||||||
|
--toggle-button-bg-hover: var(--default-hover);
|
||||||
|
--toggle-button-bg-pressed: var(--default-hover);
|
||||||
|
--toggle-button-fg: currentColor;
|
||||||
|
|
||||||
|
/* Selected state tokens */
|
||||||
|
--toggle-button-bg-selected: var(--accent-soft);
|
||||||
|
--toggle-button-bg-selected-hover: var(--accent-soft-hover);
|
||||||
|
--toggle-button-bg-selected-pressed: var(--accent-soft-hover);
|
||||||
|
--toggle-button-fg-selected: var(--accent-soft-foreground);
|
||||||
|
|
||||||
|
background-color: var(--toggle-button-bg);
|
||||||
|
color: var(--toggle-button-fg);
|
||||||
|
|
||||||
|
/* Focus state */
|
||||||
|
&:focus-visible:not([data-focused]),
|
||||||
|
&[data-focus-visible="true"] {
|
||||||
|
@apply status-focused;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disabled state */
|
||||||
|
&:disabled,
|
||||||
|
&[aria-disabled="true"] {
|
||||||
|
@apply status-disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hover */
|
||||||
|
@media (hover: hover) {
|
||||||
|
&:hover,
|
||||||
|
&[data-hovered="true"] {
|
||||||
|
background-color: var(--toggle-button-bg-hover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Active / pressed */
|
||||||
|
&:active,
|
||||||
|
&[data-pressed="true"] {
|
||||||
|
background-color: var(--toggle-button-bg-pressed);
|
||||||
|
transform: scale(0.97);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Selected state */
|
||||||
|
&[data-selected="true"] {
|
||||||
|
background-color: var(--toggle-button-bg-selected);
|
||||||
|
color: var(--toggle-button-fg-selected);
|
||||||
|
|
||||||
|
@media (hover: hover) {
|
||||||
|
&:hover,
|
||||||
|
&[data-hovered="true"] {
|
||||||
|
background-color: var(--toggle-button-bg-selected-hover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active,
|
||||||
|
&[data-pressed="true"] {
|
||||||
|
background-color: var(--toggle-button-bg-selected-pressed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SVG icon styling */
|
||||||
|
& svg {
|
||||||
|
@apply pointer-events-none -mx-0.5 my-0.5 size-5 shrink-0 self-center sm:my-1 sm:size-4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Size variants
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-toggle-button--sm {
|
||||||
|
@apply h-9 px-3 md:h-8;
|
||||||
|
|
||||||
|
& svg {
|
||||||
|
@apply size-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active,
|
||||||
|
&[data-pressed="true"] {
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button--md {
|
||||||
|
/* No styles as this is the default size */
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button--lg {
|
||||||
|
@apply h-11 text-base md:h-10;
|
||||||
|
|
||||||
|
&:active,
|
||||||
|
&[data-pressed="true"] {
|
||||||
|
transform: scale(0.96);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Variant styles
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-toggle-button--default {
|
||||||
|
--toggle-button-bg: var(--default);
|
||||||
|
--toggle-button-bg-hover: var(--default-hover);
|
||||||
|
--toggle-button-bg-pressed: var(--default-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button--ghost {
|
||||||
|
--toggle-button-bg: transparent;
|
||||||
|
--toggle-button-bg-hover: var(--default);
|
||||||
|
--toggle-button-bg-pressed: var(--default);
|
||||||
|
--toggle-button-fg: var(--default-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Icon-only modifier
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
.hv-toggle-button--icon-only {
|
||||||
|
@apply w-10 p-0 md:w-9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button--icon-only.hv-toggle-button--sm {
|
||||||
|
@apply w-9 md:w-8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hv-toggle-button--icon-only.hv-toggle-button--lg {
|
||||||
|
@apply w-11 md:w-10;
|
||||||
|
}
|
||||||
@@ -130,3 +130,6 @@
|
|||||||
|
|
||||||
@import "./components/scroll-shadow.css";
|
@import "./components/scroll-shadow.css";
|
||||||
@import "./components/tabs.css";
|
@import "./components/tabs.css";
|
||||||
|
@import "./components/button-group.css" layer(components);
|
||||||
|
@import "./components/toggle-button.css" layer(components);
|
||||||
|
@import "./components/toggle-button-group.css" layer(components);
|
||||||
|
|||||||
@@ -1056,3 +1056,95 @@ export type TabsVariants = Omit<
|
|||||||
VariantProps<typeof tabsVariants>,
|
VariantProps<typeof tabsVariants>,
|
||||||
TabsRenderPropsKeys
|
TabsRenderPropsKeys
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export const buttonGroupVariants = tv({
|
||||||
|
defaultVariants: {
|
||||||
|
fullWidth: false,
|
||||||
|
orientation: "horizontal",
|
||||||
|
},
|
||||||
|
slots: {
|
||||||
|
base: "hv-button-group",
|
||||||
|
separator: "hv-button-group__separator",
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
fullWidth: {
|
||||||
|
false: {},
|
||||||
|
true: {
|
||||||
|
base: "hv-button-group--full-width",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
orientation: {
|
||||||
|
horizontal: {
|
||||||
|
base: "hv-button-group--horizontal",
|
||||||
|
},
|
||||||
|
vertical: {
|
||||||
|
base: "hv-button-group--vertical",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ButtonGroupVariants = VariantProps<typeof buttonGroupVariants>;
|
||||||
|
|
||||||
|
export const toggleButtonVariants = tv({
|
||||||
|
base: "hv-toggle-button",
|
||||||
|
defaultVariants: {
|
||||||
|
isIconOnly: false,
|
||||||
|
size: "md",
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
isIconOnly: {
|
||||||
|
true: "hv-toggle-button--icon-only",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
lg: "hv-toggle-button--lg",
|
||||||
|
md: "hv-toggle-button--md",
|
||||||
|
sm: "hv-toggle-button--sm",
|
||||||
|
},
|
||||||
|
variant: {
|
||||||
|
default: "hv-toggle-button--default",
|
||||||
|
ghost: "hv-toggle-button--ghost",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ToggleButtonVariants = VariantProps<typeof toggleButtonVariants>;
|
||||||
|
|
||||||
|
export const toggleButtonGroupVariants = tv({
|
||||||
|
defaultVariants: {
|
||||||
|
fullWidth: false,
|
||||||
|
isDetached: false,
|
||||||
|
orientation: "horizontal",
|
||||||
|
},
|
||||||
|
slots: {
|
||||||
|
base: "hv-toggle-button-group",
|
||||||
|
separator: "hv-toggle-button-group__separator",
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
fullWidth: {
|
||||||
|
false: {},
|
||||||
|
true: {
|
||||||
|
base: "hv-toggle-button-group--full-width",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isDetached: {
|
||||||
|
false: {},
|
||||||
|
true: {
|
||||||
|
base: "hv-toggle-button-group--detached",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
orientation: {
|
||||||
|
horizontal: {
|
||||||
|
base: "hv-toggle-button-group--horizontal",
|
||||||
|
},
|
||||||
|
vertical: {
|
||||||
|
base: "hv-toggle-button-group--vertical",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ToggleButtonGroupVariants = VariantProps<
|
||||||
|
typeof toggleButtonGroupVariants
|
||||||
|
>;
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
Comment,
|
||||||
|
Fragment,
|
||||||
|
Text,
|
||||||
|
cloneVNode,
|
||||||
|
computed,
|
||||||
|
defineComponent,
|
||||||
|
h,
|
||||||
|
inject,
|
||||||
|
isVNode,
|
||||||
|
provide,
|
||||||
|
useAttrs,
|
||||||
|
type PropType,
|
||||||
|
type VNode,
|
||||||
|
type VNodeChild,
|
||||||
|
} from "vue";
|
||||||
|
import { buttonGroupVariants, type ButtonVariants } from "@heroui-vue/styles";
|
||||||
|
import { buttonGroupContextKey, buttonGroupOrientationKey } from "./context";
|
||||||
|
|
||||||
|
function flattenChildren(nodes: VNodeChild[], out: VNode[] = []): VNode[] {
|
||||||
|
for (const child of nodes) {
|
||||||
|
if (Array.isArray(child)) {
|
||||||
|
flattenChildren(child, out);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!isVNode(child)) continue;
|
||||||
|
if (child.type === Comment || child.type === Text) continue;
|
||||||
|
if (child.type === Fragment && Array.isArray(child.children)) {
|
||||||
|
flattenChildren(child.children as VNodeChild[], out);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out.push(child);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "ButtonGroup",
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
size: {
|
||||||
|
type: String as PropType<ButtonVariants["size"]>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
variant: {
|
||||||
|
type: String as PropType<ButtonVariants["variant"]>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
orientation: {
|
||||||
|
type: String as PropType<"horizontal" | "vertical">,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
fullWidth: { type: Boolean, default: false },
|
||||||
|
isDisabled: { type: Boolean, default: false },
|
||||||
|
disabled: { type: Boolean, default: false },
|
||||||
|
as: { type: String, default: "div" },
|
||||||
|
},
|
||||||
|
setup(props, { attrs, slots }) {
|
||||||
|
const inheritedOrientation = inject(buttonGroupOrientationKey, undefined);
|
||||||
|
const orientation = computed(
|
||||||
|
() => props.orientation ?? inheritedOrientation?.value ?? "horizontal",
|
||||||
|
);
|
||||||
|
const isDisabled = computed(() => props.isDisabled || props.disabled);
|
||||||
|
|
||||||
|
const groupContext = computed(() => ({
|
||||||
|
slots: buttonGroupVariants({
|
||||||
|
fullWidth: props.fullWidth,
|
||||||
|
orientation: orientation.value,
|
||||||
|
}),
|
||||||
|
size: props.size,
|
||||||
|
variant: props.variant,
|
||||||
|
isDisabled: isDisabled.value,
|
||||||
|
fullWidth: props.fullWidth,
|
||||||
|
orientation: orientation.value,
|
||||||
|
}));
|
||||||
|
|
||||||
|
provide(buttonGroupContextKey, groupContext);
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
const flat = flattenChildren((slots.default?.() ?? []) as VNodeChild[]);
|
||||||
|
// Only component children accept the marker; native nodes must not leak props.
|
||||||
|
const children = flat.map((child) =>
|
||||||
|
typeof child.type === "object" && child.type !== null
|
||||||
|
? cloneVNode(child, { __button_group_child: true })
|
||||||
|
: child,
|
||||||
|
);
|
||||||
|
return h(
|
||||||
|
props.as,
|
||||||
|
{
|
||||||
|
...attrs,
|
||||||
|
role: "group",
|
||||||
|
class: [groupContext.value.slots.base(), attrs.class],
|
||||||
|
"data-slot": "button-group",
|
||||||
|
"aria-disabled": isDisabled.value || undefined,
|
||||||
|
},
|
||||||
|
children,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return render;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { Primitive } from "reka-ui";
|
||||||
|
import { buttonGroupContextKey } from "./context";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
const props = defineProps<{
|
||||||
|
/** Absorbs direct-child markers; not a public API. */
|
||||||
|
__button_group_child?: boolean;
|
||||||
|
}>();
|
||||||
|
void props;
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const group = inject(buttonGroupContextKey, undefined);
|
||||||
|
const separatorClass = computed(() => group?.value.slots.separator());
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<Primitive
|
||||||
|
as="span"
|
||||||
|
aria-hidden="true"
|
||||||
|
:class="[separatorClass, attrs.class]"
|
||||||
|
data-slot="button-group-separator"
|
||||||
|
v-bind="{ ...attrs, class: undefined }"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</Primitive>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import type { ComputedRef, InjectionKey } from "vue";
|
||||||
|
import type { ButtonVariants, buttonGroupVariants } from "@heroui-vue/styles";
|
||||||
|
|
||||||
|
/** Marks direct children of ButtonGroup so nested Buttons do not inherit group props. */
|
||||||
|
export const BUTTON_GROUP_CHILD = "__button_group_child" as const;
|
||||||
|
|
||||||
|
export type ButtonGroupSlots = ReturnType<typeof buttonGroupVariants>;
|
||||||
|
|
||||||
|
export interface ButtonGroupContextValue {
|
||||||
|
slots: ButtonGroupSlots;
|
||||||
|
size?: ButtonVariants["size"];
|
||||||
|
variant?: ButtonVariants["variant"];
|
||||||
|
isDisabled?: boolean;
|
||||||
|
fullWidth?: boolean;
|
||||||
|
orientation: "horizontal" | "vertical";
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ButtonGroupContext = ComputedRef<ButtonGroupContextValue>;
|
||||||
|
|
||||||
|
export const buttonGroupContextKey: InjectionKey<ButtonGroupContext> = Symbol(
|
||||||
|
"HeroUIVue.ButtonGroup",
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Orientation inherited by ButtonGroup when nested in ToggleButtonGroup. */
|
||||||
|
export const buttonGroupOrientationKey: InjectionKey<
|
||||||
|
ComputedRef<"horizontal" | "vertical">
|
||||||
|
> = Symbol("HeroUIVue.ButtonGroupOrientation");
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useInheritedDisabled } from "../field/disabled";
|
import { useInheritedDisabled } from "../field/disabled";
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, inject, ref, watch } from "vue";
|
||||||
import { Primitive } from "reka-ui";
|
import { Primitive } from "reka-ui";
|
||||||
import type { ButtonHTMLAttributes } from "vue";
|
import type { ButtonHTMLAttributes } from "vue";
|
||||||
import { buttonVariants, type ButtonVariants } from "@heroui-vue/styles";
|
import { buttonVariants, type ButtonVariants } from "@heroui-vue/styles";
|
||||||
import Spinner from "../spinner/Spinner.vue";
|
import Spinner from "../spinner/Spinner.vue";
|
||||||
|
import { buttonGroupContextKey } from "../button-group/context";
|
||||||
defineOptions({ inheritAttrs: false });
|
defineOptions({ inheritAttrs: false });
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@@ -18,11 +19,56 @@ const props = withDefaults(
|
|||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
type?: ButtonHTMLAttributes["type"];
|
type?: ButtonHTMLAttributes["type"];
|
||||||
|
/** Marks a direct ButtonGroup child (see BUTTON_GROUP_CHILD). */
|
||||||
|
__button_group_child?: boolean;
|
||||||
}>(),
|
}>(),
|
||||||
{ type: "button" },
|
{
|
||||||
|
type: "button",
|
||||||
|
variant: undefined,
|
||||||
|
size: undefined,
|
||||||
|
fullWidth: undefined,
|
||||||
|
isDisabled: undefined,
|
||||||
|
disabled: undefined,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const buttonGroupContext = inject(buttonGroupContextKey, undefined);
|
||||||
|
const isButtonGroupChild = computed(() => props.__button_group_child === true);
|
||||||
|
const finalSize = computed(
|
||||||
|
() =>
|
||||||
|
props.size ??
|
||||||
|
(isButtonGroupChild.value ? buttonGroupContext?.value.size : undefined),
|
||||||
|
);
|
||||||
|
const finalVariant = computed(
|
||||||
|
() =>
|
||||||
|
props.variant ??
|
||||||
|
(isButtonGroupChild.value ? buttonGroupContext?.value.variant : undefined),
|
||||||
|
);
|
||||||
|
const finalFullWidth = computed(
|
||||||
|
() =>
|
||||||
|
props.fullWidth ??
|
||||||
|
(isButtonGroupChild.value
|
||||||
|
? buttonGroupContext?.value.fullWidth
|
||||||
|
: undefined),
|
||||||
|
);
|
||||||
|
const groupDisabled = computed(() =>
|
||||||
|
isButtonGroupChild.value
|
||||||
|
? Boolean(buttonGroupContext?.value.isDisabled)
|
||||||
|
: false,
|
||||||
|
);
|
||||||
|
/**
|
||||||
|
* Upstream nullish precedence: explicit child props override ButtonGroup defaults.
|
||||||
|
* Fieldset/native constraints still force disabled through useInheritedDisabled.
|
||||||
|
*/
|
||||||
|
const explicitDisabled = computed(
|
||||||
|
() => props.isDisabled ?? props.disabled ?? undefined,
|
||||||
|
);
|
||||||
|
const localDisabled = computed(() =>
|
||||||
|
explicitDisabled.value === undefined
|
||||||
|
? groupDisabled.value
|
||||||
|
: Boolean(explicitDisabled.value),
|
||||||
);
|
);
|
||||||
const pending = computed(() => props.isPending || props.loading);
|
const pending = computed(() => props.isPending || props.loading);
|
||||||
const disabled = useInheritedDisabled(() => props.isDisabled || props.disabled);
|
const disabled = useInheritedDisabled(() => localDisabled.value);
|
||||||
const hovered = ref(false),
|
const hovered = ref(false),
|
||||||
pressed = ref(false),
|
pressed = ref(false),
|
||||||
focused = ref(false),
|
focused = ref(false),
|
||||||
@@ -55,7 +101,14 @@ function focus(e: FocusEvent) {
|
|||||||
:as-child="asChild"
|
:as-child="asChild"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
:type="type"
|
:type="type"
|
||||||
:class="buttonVariants({ variant, size, fullWidth, isIconOnly })"
|
:class="
|
||||||
|
buttonVariants({
|
||||||
|
variant: finalVariant,
|
||||||
|
size: finalSize,
|
||||||
|
fullWidth: finalFullWidth,
|
||||||
|
isIconOnly,
|
||||||
|
})
|
||||||
|
"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:aria-disabled="pending || disabled || undefined"
|
:aria-disabled="pending || disabled || undefined"
|
||||||
:aria-busy="pending || undefined"
|
:aria-busy="pending || undefined"
|
||||||
|
|||||||
@@ -0,0 +1,197 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
Comment,
|
||||||
|
Fragment,
|
||||||
|
Text,
|
||||||
|
computed,
|
||||||
|
defineComponent,
|
||||||
|
h,
|
||||||
|
isVNode,
|
||||||
|
provide,
|
||||||
|
useAttrs,
|
||||||
|
type PropType,
|
||||||
|
type VNodeChild,
|
||||||
|
} from "vue";
|
||||||
|
import {
|
||||||
|
toggleButtonGroupVariants,
|
||||||
|
type ToggleButtonVariants,
|
||||||
|
} from "@heroui-vue/styles";
|
||||||
|
import { buttonGroupOrientationKey } from "../button-group/context";
|
||||||
|
import { useConfig } from "../../providers/context";
|
||||||
|
import {
|
||||||
|
toggleButtonGroupKey,
|
||||||
|
type ToggleButtonGroupKey,
|
||||||
|
type ToggleButtonGroupContextValue,
|
||||||
|
} from "./context";
|
||||||
|
import {
|
||||||
|
useToggleButtonSelection,
|
||||||
|
useToggleRovingFocus,
|
||||||
|
type ToggleButtonGroupSelection,
|
||||||
|
} from "./useToggleButtonSelection";
|
||||||
|
|
||||||
|
function flattenChildren(
|
||||||
|
nodes: VNodeChild[],
|
||||||
|
out: VNodeChild[] = [],
|
||||||
|
): VNodeChild[] {
|
||||||
|
for (const child of nodes) {
|
||||||
|
if (Array.isArray(child)) {
|
||||||
|
flattenChildren(child, out);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
isVNode(child) &&
|
||||||
|
child.type === Fragment &&
|
||||||
|
Array.isArray(child.children)
|
||||||
|
) {
|
||||||
|
flattenChildren(child.children as VNodeChild[], out);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out.push(child);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "ToggleButtonGroup",
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
selectionMode: {
|
||||||
|
type: String as PropType<"single" | "multiple">,
|
||||||
|
default: "single",
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: [
|
||||||
|
String,
|
||||||
|
Number,
|
||||||
|
Array,
|
||||||
|
null,
|
||||||
|
] as PropType<ToggleButtonGroupSelection>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
defaultValue: {
|
||||||
|
type: [
|
||||||
|
String,
|
||||||
|
Number,
|
||||||
|
Array,
|
||||||
|
null,
|
||||||
|
] as PropType<ToggleButtonGroupSelection>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
selectedKeys: {
|
||||||
|
type: [
|
||||||
|
String,
|
||||||
|
Number,
|
||||||
|
Array,
|
||||||
|
null,
|
||||||
|
] as PropType<ToggleButtonGroupSelection>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
defaultSelectedKeys: {
|
||||||
|
type: [
|
||||||
|
String,
|
||||||
|
Number,
|
||||||
|
Array,
|
||||||
|
null,
|
||||||
|
] as PropType<ToggleButtonGroupSelection>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
disallowEmptySelection: { type: Boolean, default: false },
|
||||||
|
orientation: {
|
||||||
|
type: String as PropType<"horizontal" | "vertical">,
|
||||||
|
default: "horizontal",
|
||||||
|
},
|
||||||
|
dir: {
|
||||||
|
type: String as PropType<"ltr" | "rtl">,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: String as PropType<ToggleButtonVariants["size"]>,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
isDetached: { type: Boolean, default: false },
|
||||||
|
fullWidth: { type: Boolean, default: false },
|
||||||
|
isDisabled: { type: Boolean, default: false },
|
||||||
|
disabled: { type: Boolean, default: false },
|
||||||
|
as: { type: String, default: "div" },
|
||||||
|
},
|
||||||
|
emits: {
|
||||||
|
"update:modelValue": (
|
||||||
|
_value: ToggleButtonGroupKey[] | ToggleButtonGroupKey | null,
|
||||||
|
) => true,
|
||||||
|
selectionChange: (
|
||||||
|
_value: ToggleButtonGroupKey[] | ToggleButtonGroupKey | null,
|
||||||
|
) => true,
|
||||||
|
},
|
||||||
|
setup(props, { attrs, slots, emit }) {
|
||||||
|
const isSingle = computed(() => props.selectionMode !== "multiple");
|
||||||
|
const isDisabled = computed(() => props.isDisabled || props.disabled);
|
||||||
|
const orientation = computed(() => props.orientation);
|
||||||
|
const config = useConfig();
|
||||||
|
const dir = computed<"ltr" | "rtl">(
|
||||||
|
() => props.dir ?? config?.dir.value ?? "ltr",
|
||||||
|
);
|
||||||
|
|
||||||
|
const selection = useToggleButtonSelection({
|
||||||
|
isSingle: () => isSingle.value,
|
||||||
|
read: () => props.selectedKeys ?? props.modelValue,
|
||||||
|
defaults: () => props.defaultSelectedKeys ?? props.defaultValue,
|
||||||
|
keys: ["modelValue", "model-value", "selectedKeys", "selected-keys"],
|
||||||
|
disallowEmptySelection: () => props.disallowEmptySelection,
|
||||||
|
emit: (value) => {
|
||||||
|
emit("update:modelValue", value);
|
||||||
|
emit("selectionChange", value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const roving = useToggleRovingFocus({
|
||||||
|
orientation: () => orientation.value,
|
||||||
|
dir: () => dir.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
const slotsMap = computed(() =>
|
||||||
|
toggleButtonGroupVariants({
|
||||||
|
fullWidth: props.fullWidth,
|
||||||
|
isDetached: props.isDetached,
|
||||||
|
orientation: orientation.value,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const size = computed(() => props.size);
|
||||||
|
|
||||||
|
const groupContext: ToggleButtonGroupContextValue = {
|
||||||
|
slots: slotsMap,
|
||||||
|
size,
|
||||||
|
isDisabled,
|
||||||
|
isSingle,
|
||||||
|
selected: selection.selected,
|
||||||
|
change: selection.request,
|
||||||
|
orientation,
|
||||||
|
dir,
|
||||||
|
tabIndex: roving.tabIndex,
|
||||||
|
register: (key, el, disabled) => roving.register({ key, el, disabled }),
|
||||||
|
keydown: roving.keydown,
|
||||||
|
noteFocus: roving.noteFocus,
|
||||||
|
};
|
||||||
|
|
||||||
|
provide(toggleButtonGroupKey, groupContext);
|
||||||
|
provide(buttonGroupOrientationKey, orientation);
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return h(
|
||||||
|
props.as,
|
||||||
|
{
|
||||||
|
...attrs,
|
||||||
|
role: isSingle.value ? "radiogroup" : "toolbar",
|
||||||
|
class: [slotsMap.value.base(), attrs.class],
|
||||||
|
"data-slot": "toggle-button-group",
|
||||||
|
"aria-disabled": isDisabled.value || undefined,
|
||||||
|
"aria-orientation": orientation.value,
|
||||||
|
dir: dir.value,
|
||||||
|
},
|
||||||
|
flattenChildren((slots.default?.() ?? []) as VNodeChild[]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return render;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, useAttrs } from "vue";
|
||||||
|
import { Primitive } from "reka-ui";
|
||||||
|
import { toggleButtonGroupKey } from "./context";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
const props = defineProps<{
|
||||||
|
/** Absorbs group child markers; not a public API. */
|
||||||
|
__button_group_child?: boolean;
|
||||||
|
}>();
|
||||||
|
void props;
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const group = inject(toggleButtonGroupKey, undefined);
|
||||||
|
const separatorClass = computed(() => group?.slots.value.separator());
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<Primitive
|
||||||
|
as="span"
|
||||||
|
aria-hidden="true"
|
||||||
|
:class="[separatorClass, attrs.class]"
|
||||||
|
data-slot="toggle-button-group-separator"
|
||||||
|
v-bind="{ ...attrs, class: undefined }"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</Primitive>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { ComputedRef, InjectionKey } from "vue";
|
||||||
|
import type {
|
||||||
|
ToggleButtonVariants,
|
||||||
|
toggleButtonGroupVariants,
|
||||||
|
} from "@heroui-vue/styles";
|
||||||
|
|
||||||
|
export type ToggleButtonGroupKey = string | number;
|
||||||
|
|
||||||
|
export interface ToggleButtonGroupContextValue {
|
||||||
|
slots: ComputedRef<ReturnType<typeof toggleButtonGroupVariants>>;
|
||||||
|
size: ComputedRef<ToggleButtonVariants["size"] | undefined>;
|
||||||
|
isDisabled: ComputedRef<boolean>;
|
||||||
|
isSingle: ComputedRef<boolean>;
|
||||||
|
selected: (key: ToggleButtonGroupKey) => boolean;
|
||||||
|
change: (key: ToggleButtonGroupKey) => void;
|
||||||
|
orientation: ComputedRef<"horizontal" | "vertical">;
|
||||||
|
dir: ComputedRef<"ltr" | "rtl">;
|
||||||
|
/** Roving tabindex for the active member key. */
|
||||||
|
tabIndex: (key: ToggleButtonGroupKey) => number;
|
||||||
|
/** Register a member for keyboard order; returns unregister. */
|
||||||
|
register: (
|
||||||
|
key: ToggleButtonGroupKey,
|
||||||
|
el: () => HTMLElement | undefined,
|
||||||
|
disabled: ComputedRef<boolean>,
|
||||||
|
) => () => void;
|
||||||
|
/** Arrow-key navigation within the group. */
|
||||||
|
keydown: (event: KeyboardEvent, key: ToggleButtonGroupKey) => void;
|
||||||
|
/** Sync the single Tab entry after a real focus, without moving focus. */
|
||||||
|
noteFocus: (key: ToggleButtonGroupKey) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const toggleButtonGroupKey: InjectionKey<ToggleButtonGroupContextValue> =
|
||||||
|
Symbol("HeroUIVue.ToggleButtonGroup");
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
import {
|
||||||
|
computed,
|
||||||
|
getCurrentInstance,
|
||||||
|
onBeforeUpdate,
|
||||||
|
ref,
|
||||||
|
watch,
|
||||||
|
type ComputedRef,
|
||||||
|
type Ref,
|
||||||
|
} from "vue";
|
||||||
|
import type { ToggleButtonGroupKey } from "./context";
|
||||||
|
|
||||||
|
export type ToggleButtonGroupSelection =
|
||||||
|
ToggleButtonGroupKey | ToggleButtonGroupKey[] | null | undefined;
|
||||||
|
|
||||||
|
function toArray(value: ToggleButtonGroupSelection): ToggleButtonGroupKey[] {
|
||||||
|
if (value == null) return [];
|
||||||
|
return Array.isArray(value) ? [...value] : [value];
|
||||||
|
}
|
||||||
|
|
||||||
|
function sameKey(a: ToggleButtonGroupKey, b: ToggleButtonGroupKey): boolean {
|
||||||
|
return a === b;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalize(
|
||||||
|
raw: ToggleButtonGroupSelection,
|
||||||
|
single: boolean,
|
||||||
|
): ToggleButtonGroupKey[] | ToggleButtonGroupKey | null {
|
||||||
|
const list = toArray(raw);
|
||||||
|
return single ? (list[0] ?? null) : list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlled/uncontrolled selection for ToggleButtonGroup.
|
||||||
|
* Single mode stores one key or null; multiple mode stores an array.
|
||||||
|
* Mode switches collapse internal state so single mode never keeps >1 key.
|
||||||
|
*/
|
||||||
|
export function useToggleButtonSelection(options: {
|
||||||
|
isSingle: () => boolean;
|
||||||
|
read: () => ToggleButtonGroupSelection;
|
||||||
|
defaults: () => ToggleButtonGroupSelection;
|
||||||
|
keys: string[];
|
||||||
|
disallowEmptySelection: () => boolean;
|
||||||
|
emit: (value: ToggleButtonGroupKey[] | ToggleButtonGroupKey | null) => void;
|
||||||
|
}) {
|
||||||
|
const instance = getCurrentInstance();
|
||||||
|
const copy = <T>(value: T): T =>
|
||||||
|
(Array.isArray(value) ? [...value] : value) as T;
|
||||||
|
|
||||||
|
const initial = copy(normalize(options.defaults(), options.isSingle())) as
|
||||||
|
ToggleButtonGroupKey[] | ToggleButtonGroupKey | null;
|
||||||
|
const internal = ref(initial) as Ref<
|
||||||
|
ToggleButtonGroupKey[] | ToggleButtonGroupKey | null
|
||||||
|
>;
|
||||||
|
|
||||||
|
const controlled = () =>
|
||||||
|
options.keys.some((key) => Object.hasOwn(instance?.vnode.props ?? {}, key));
|
||||||
|
const isControlled = ref(controlled());
|
||||||
|
onBeforeUpdate(() => {
|
||||||
|
isControlled.value = controlled();
|
||||||
|
});
|
||||||
|
|
||||||
|
const value = computed(() => {
|
||||||
|
const external = normalize(options.read(), options.isSingle());
|
||||||
|
return isControlled.value ? external : internal.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reconcile uncontrolled internal shape when selectionMode flips.
|
||||||
|
watch(
|
||||||
|
() => options.isSingle(),
|
||||||
|
(single) => {
|
||||||
|
if (controlled()) return;
|
||||||
|
const list = toArray(internal.value);
|
||||||
|
const next = single ? (list[0] ?? null) : list;
|
||||||
|
internal.value = copy(next);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
function selected(key: ToggleButtonGroupKey): boolean {
|
||||||
|
return toArray(value.value).some((item) => sameKey(item, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
function request(key: ToggleButtonGroupKey) {
|
||||||
|
const single = options.isSingle();
|
||||||
|
const current = toArray(value.value);
|
||||||
|
let next: ToggleButtonGroupKey[];
|
||||||
|
|
||||||
|
if (single) {
|
||||||
|
const already = current.some((item) => sameKey(item, key));
|
||||||
|
if (already && options.disallowEmptySelection()) return;
|
||||||
|
next = already ? [] : [key];
|
||||||
|
} else {
|
||||||
|
const index = current.findIndex((item) => sameKey(item, key));
|
||||||
|
if (index >= 0) {
|
||||||
|
if (current.length === 1 && options.disallowEmptySelection()) return;
|
||||||
|
next = current.filter((_, i) => i !== index);
|
||||||
|
} else {
|
||||||
|
next = [...current, key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = single ? (next[0] ?? null) : next;
|
||||||
|
if (!controlled()) internal.value = copy(payload);
|
||||||
|
options.emit(copy(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
return { value, selected, request };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ToggleMember {
|
||||||
|
key: ToggleButtonGroupKey;
|
||||||
|
el: () => HTMLElement | undefined;
|
||||||
|
disabled: ComputedRef<boolean>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function domOrder(members: ToggleMember[]): ToggleMember[] {
|
||||||
|
const placed = members.map((m) => ({ m, el: m.el() }));
|
||||||
|
const withEl = placed.filter(
|
||||||
|
(p): p is { m: ToggleMember; el: HTMLElement } => !!p.el,
|
||||||
|
);
|
||||||
|
const without = placed.filter((p) => !p.el).map((p) => p.m);
|
||||||
|
withEl.sort((a, b) => {
|
||||||
|
const pos = a.el.compareDocumentPosition(b.el);
|
||||||
|
if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
||||||
|
if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
return [...withEl.map((p) => p.m), ...without];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Roving tabindex with a single Tab stop per group.
|
||||||
|
* Navigation follows live DOM order; real focus updates the Tab entry.
|
||||||
|
* Arrow keys follow orientation + dir; cancelled events are ignored.
|
||||||
|
*/
|
||||||
|
export function useToggleRovingFocus(options: {
|
||||||
|
orientation: () => "horizontal" | "vertical";
|
||||||
|
dir: () => "ltr" | "rtl";
|
||||||
|
}) {
|
||||||
|
const members = new Map<ToggleButtonGroupKey, ToggleMember>();
|
||||||
|
const version = ref(0);
|
||||||
|
const active = ref<ToggleButtonGroupKey | null>(null);
|
||||||
|
const stops = new Map<ToggleButtonGroupKey, () => void>();
|
||||||
|
|
||||||
|
function bump() {
|
||||||
|
version.value++;
|
||||||
|
}
|
||||||
|
|
||||||
|
function register(member: ToggleMember) {
|
||||||
|
members.set(member.key, member);
|
||||||
|
bump();
|
||||||
|
const stop = watch(
|
||||||
|
member.disabled,
|
||||||
|
() => {
|
||||||
|
if (member.disabled.value && active.value === member.key) {
|
||||||
|
active.value = ordered()[0]?.key ?? null;
|
||||||
|
}
|
||||||
|
bump();
|
||||||
|
},
|
||||||
|
{ flush: "sync" },
|
||||||
|
);
|
||||||
|
stops.set(member.key, stop);
|
||||||
|
if (
|
||||||
|
active.value == null ||
|
||||||
|
!members.has(active.value) ||
|
||||||
|
members.get(active.value)?.disabled.value
|
||||||
|
) {
|
||||||
|
active.value = ordered()[0]?.key ?? member.key;
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
stop();
|
||||||
|
stops.delete(member.key);
|
||||||
|
members.delete(member.key);
|
||||||
|
if (active.value === member.key) {
|
||||||
|
active.value = ordered()[0]?.key ?? null;
|
||||||
|
}
|
||||||
|
bump();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function ordered(): ToggleMember[] {
|
||||||
|
void version.value;
|
||||||
|
return domOrder([...members.values()].filter((m) => !m.disabled.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sync Tab entry to a real focus target without re-calling focus(). */
|
||||||
|
function noteFocus(key: ToggleButtonGroupKey) {
|
||||||
|
const member = members.get(key);
|
||||||
|
if (!member || member.disabled.value) return;
|
||||||
|
if (active.value === key) return;
|
||||||
|
active.value = key;
|
||||||
|
bump();
|
||||||
|
}
|
||||||
|
|
||||||
|
function tabIndex(key: ToggleButtonGroupKey): number {
|
||||||
|
const list = ordered();
|
||||||
|
if (!list.length) return 0;
|
||||||
|
const current = active.value ?? list[0]!.key;
|
||||||
|
return sameKey(key, current) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function focusKey(key: ToggleButtonGroupKey) {
|
||||||
|
active.value = key;
|
||||||
|
bump();
|
||||||
|
members.get(key)?.el()?.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function keydown(event: KeyboardEvent, key: ToggleButtonGroupKey) {
|
||||||
|
if (event.defaultPrevented) return;
|
||||||
|
const list = ordered();
|
||||||
|
if (!list.length) return;
|
||||||
|
const index = list.findIndex((m) => sameKey(m.key, key));
|
||||||
|
if (index < 0) return;
|
||||||
|
|
||||||
|
const horizontal = options.orientation() === "horizontal";
|
||||||
|
const rtl = options.dir() === "rtl";
|
||||||
|
let nextIndex = index;
|
||||||
|
|
||||||
|
if (horizontal) {
|
||||||
|
switch (event.key) {
|
||||||
|
case "ArrowRight":
|
||||||
|
nextIndex = rtl
|
||||||
|
? (index - 1 + list.length) % list.length
|
||||||
|
: (index + 1) % list.length;
|
||||||
|
break;
|
||||||
|
case "ArrowLeft":
|
||||||
|
nextIndex = rtl
|
||||||
|
? (index + 1) % list.length
|
||||||
|
: (index - 1 + list.length) % list.length;
|
||||||
|
break;
|
||||||
|
case "Home":
|
||||||
|
nextIndex = 0;
|
||||||
|
break;
|
||||||
|
case "End":
|
||||||
|
nextIndex = list.length - 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (event.key) {
|
||||||
|
case "ArrowDown":
|
||||||
|
nextIndex = (index + 1) % list.length;
|
||||||
|
break;
|
||||||
|
case "ArrowUp":
|
||||||
|
nextIndex = (index - 1 + list.length) % list.length;
|
||||||
|
break;
|
||||||
|
case "Home":
|
||||||
|
nextIndex = 0;
|
||||||
|
break;
|
||||||
|
case "End":
|
||||||
|
nextIndex = list.length - 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
const next = list[nextIndex]!;
|
||||||
|
focusKey(next.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { register, tabIndex, keydown, noteFocus, active, version };
|
||||||
|
}
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, onBeforeUnmount, ref, useAttrs, watch } from "vue";
|
||||||
|
import { Primitive } from "reka-ui";
|
||||||
|
import {
|
||||||
|
toggleButtonVariants,
|
||||||
|
type ToggleButtonVariants,
|
||||||
|
} from "@heroui-vue/styles";
|
||||||
|
import {
|
||||||
|
toggleButtonGroupKey,
|
||||||
|
type ToggleButtonGroupKey,
|
||||||
|
} from "../toggle-button-group/context";
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false });
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
/** Controlled selected state (standalone). */
|
||||||
|
modelValue?: boolean | null;
|
||||||
|
isSelected?: boolean | null;
|
||||||
|
defaultValue?: boolean;
|
||||||
|
defaultSelected?: boolean;
|
||||||
|
isDisabled?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
isIconOnly?: boolean;
|
||||||
|
size?: ToggleButtonVariants["size"];
|
||||||
|
variant?: ToggleButtonVariants["variant"];
|
||||||
|
/** Group member key (upstream `id` in selectedKeys). Not used as DOM id. */
|
||||||
|
id?: ToggleButtonGroupKey;
|
||||||
|
value?: ToggleButtonGroupKey;
|
||||||
|
asChild?: boolean;
|
||||||
|
/** Absorbs ButtonGroup-style child markers; not a public API. */
|
||||||
|
__button_group_child?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
modelValue: undefined,
|
||||||
|
isSelected: undefined,
|
||||||
|
variant: undefined,
|
||||||
|
size: undefined,
|
||||||
|
isDisabled: undefined,
|
||||||
|
disabled: undefined,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"update:modelValue": [value: boolean];
|
||||||
|
change: [value: boolean];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const group = inject(toggleButtonGroupKey, undefined);
|
||||||
|
const groupKey = computed<ToggleButtonGroupKey | null>(() => {
|
||||||
|
const key = props.value ?? props.id;
|
||||||
|
return key === undefined || key === null ? null : key;
|
||||||
|
});
|
||||||
|
const inGroup = computed(() => Boolean(group) && groupKey.value !== null);
|
||||||
|
|
||||||
|
const initial = props.defaultSelected ?? props.defaultValue ?? false;
|
||||||
|
const local = ref(Boolean(initial));
|
||||||
|
const controlled = computed(
|
||||||
|
() => props.modelValue !== undefined || props.isSelected !== undefined,
|
||||||
|
);
|
||||||
|
const standaloneSelected = computed(() =>
|
||||||
|
controlled.value
|
||||||
|
? Boolean(props.isSelected ?? props.modelValue)
|
||||||
|
: local.value,
|
||||||
|
);
|
||||||
|
|
||||||
|
const selected = computed(() =>
|
||||||
|
inGroup.value ? group!.selected(groupKey.value!) : standaloneSelected.value,
|
||||||
|
);
|
||||||
|
|
||||||
|
const groupDisabled = computed(() =>
|
||||||
|
inGroup.value ? group!.isDisabled.value : false,
|
||||||
|
);
|
||||||
|
const disabled = computed(() =>
|
||||||
|
Boolean(props.isDisabled || props.disabled || groupDisabled.value),
|
||||||
|
);
|
||||||
|
|
||||||
|
const isSingleInGroup = computed(
|
||||||
|
() => Boolean(group) && group!.isSingle.value && groupKey.value !== null,
|
||||||
|
);
|
||||||
|
|
||||||
|
function request(e: MouseEvent) {
|
||||||
|
if (e.defaultPrevented || disabled.value) return;
|
||||||
|
if (inGroup.value) {
|
||||||
|
group!.change(groupKey.value!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const next = !selected.value;
|
||||||
|
if (!controlled.value) local.value = next;
|
||||||
|
emit("update:modelValue", next);
|
||||||
|
emit("change", next);
|
||||||
|
}
|
||||||
|
|
||||||
|
const hovered = ref(false);
|
||||||
|
const pressed = ref(false);
|
||||||
|
const focused = ref(false);
|
||||||
|
const focusVisible = ref(false);
|
||||||
|
const root = ref<HTMLElement | undefined>();
|
||||||
|
let unregister: (() => void) | undefined;
|
||||||
|
|
||||||
|
function setRoot(el: unknown) {
|
||||||
|
const node = el as { $el?: HTMLElement } | HTMLElement | null;
|
||||||
|
if (!node) {
|
||||||
|
root.value = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
root.value =
|
||||||
|
node instanceof HTMLElement
|
||||||
|
? node
|
||||||
|
: ((node.$el as HTMLElement) ?? undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
disabled,
|
||||||
|
(isDisabled) => {
|
||||||
|
if (isDisabled) {
|
||||||
|
hovered.value = false;
|
||||||
|
pressed.value = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ flush: "sync" },
|
||||||
|
);
|
||||||
|
|
||||||
|
function bindRegistration() {
|
||||||
|
unregister?.();
|
||||||
|
unregister = undefined;
|
||||||
|
if (!inGroup.value || !group || groupKey.value === null) return;
|
||||||
|
unregister = group.register(groupKey.value, () => root.value, disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [inGroup.value, groupKey.value] as const,
|
||||||
|
() => {
|
||||||
|
bindRegistration();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
onBeforeUnmount(() => unregister?.());
|
||||||
|
|
||||||
|
function guard(e: MouseEvent) {
|
||||||
|
if (disabled.value) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function focus(e: FocusEvent) {
|
||||||
|
focused.value = true;
|
||||||
|
focusVisible.value = (e.target as HTMLElement).matches(":focus-visible");
|
||||||
|
if (inGroup.value && group && groupKey.value !== null) {
|
||||||
|
group.noteFocus(groupKey.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function onKeydown(e: KeyboardEvent) {
|
||||||
|
if (e.defaultPrevented) return;
|
||||||
|
if (!inGroup.value || !group || groupKey.value === null) return;
|
||||||
|
group.keydown(e, groupKey.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const finalSize = computed(() => props.size ?? group?.size.value ?? "md");
|
||||||
|
const finalVariant = computed(() => props.variant ?? "default");
|
||||||
|
|
||||||
|
/** Independent buttons keep the public `id` as DOM id; group keys stay logical. */
|
||||||
|
const domId = computed(() =>
|
||||||
|
inGroup.value ? (attrs.id as string | undefined) : props.id,
|
||||||
|
);
|
||||||
|
const tabIndex = computed(() =>
|
||||||
|
inGroup.value && group && groupKey.value !== null
|
||||||
|
? group.tabIndex(groupKey.value)
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<Primitive
|
||||||
|
:ref="setRoot"
|
||||||
|
as="button"
|
||||||
|
:as-child="asChild"
|
||||||
|
v-bind="$attrs"
|
||||||
|
:id="domId"
|
||||||
|
type="button"
|
||||||
|
:class="
|
||||||
|
toggleButtonVariants({
|
||||||
|
isIconOnly,
|
||||||
|
size: finalSize,
|
||||||
|
variant: finalVariant,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
:disabled="disabled"
|
||||||
|
:role="isSingleInGroup ? 'radio' : 'button'"
|
||||||
|
:aria-checked="isSingleInGroup ? String(selected) : undefined"
|
||||||
|
:aria-pressed="isSingleInGroup ? undefined : String(selected)"
|
||||||
|
:aria-disabled="disabled || undefined"
|
||||||
|
:tabindex="tabIndex"
|
||||||
|
:data-selected="selected || undefined"
|
||||||
|
:data-hovered="(!disabled && hovered) || undefined"
|
||||||
|
:data-pressed="(!disabled && pressed) || undefined"
|
||||||
|
:data-focused="focused || undefined"
|
||||||
|
:data-focus-visible="focusVisible || undefined"
|
||||||
|
:data-disabled="disabled || undefined"
|
||||||
|
data-slot="toggle-button"
|
||||||
|
@click.capture="guard"
|
||||||
|
@click="request"
|
||||||
|
@pointerenter="hovered = !disabled"
|
||||||
|
@pointerleave="
|
||||||
|
hovered = false;
|
||||||
|
pressed = false;
|
||||||
|
"
|
||||||
|
@pointerdown="pressed = !disabled"
|
||||||
|
@pointerup="pressed = false"
|
||||||
|
@keydown.space="pressed = !disabled"
|
||||||
|
@keydown.enter="pressed = !disabled"
|
||||||
|
@keydown="onKeydown"
|
||||||
|
@keyup="pressed = false"
|
||||||
|
@focus="focus"
|
||||||
|
@blur="
|
||||||
|
focused = false;
|
||||||
|
focusVisible = false;
|
||||||
|
pressed = false;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<slot
|
||||||
|
:is-selected="Boolean(selected)"
|
||||||
|
:is-pressed="pressed"
|
||||||
|
:is-hovered="hovered"
|
||||||
|
:is-focused="focused"
|
||||||
|
:is-focus-visible="focusVisible"
|
||||||
|
:is-disabled="Boolean(disabled)"
|
||||||
|
/>
|
||||||
|
</Primitive>
|
||||||
|
</template>
|
||||||
@@ -499,3 +499,31 @@ export type {
|
|||||||
TabsIndicatorProps,
|
TabsIndicatorProps,
|
||||||
TabsSeparatorProps,
|
TabsSeparatorProps,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
|
export { default as ButtonGroup } from "./components/button-group/ButtonGroup.vue";
|
||||||
|
export { default as ButtonGroupSeparator } from "./components/button-group/ButtonGroupSeparator.vue";
|
||||||
|
export type { ButtonGroupContextValue } from "./components/button-group/context";
|
||||||
|
export {
|
||||||
|
buttonGroupVariants,
|
||||||
|
toggleButtonVariants,
|
||||||
|
toggleButtonGroupVariants,
|
||||||
|
type ButtonGroupVariants,
|
||||||
|
type ToggleButtonVariants,
|
||||||
|
type ToggleButtonGroupVariants,
|
||||||
|
} from "@heroui-vue/styles";
|
||||||
|
|
||||||
|
export { default as ToggleButton } from "./components/toggle-button/ToggleButton.vue";
|
||||||
|
export { default as ToggleButtonGroup } from "./components/toggle-button-group/ToggleButtonGroup.vue";
|
||||||
|
export { default as ToggleButtonGroupSeparator } from "./components/toggle-button-group/ToggleButtonGroupSeparator.vue";
|
||||||
|
export type {
|
||||||
|
ToggleButtonGroupKey,
|
||||||
|
ToggleButtonGroupContextValue,
|
||||||
|
} from "./components/toggle-button-group/context";
|
||||||
|
|
||||||
|
export type {
|
||||||
|
ButtonGroupProps,
|
||||||
|
ButtonGroupSeparatorProps,
|
||||||
|
ToggleButtonProps,
|
||||||
|
ToggleButtonGroupProps,
|
||||||
|
ToggleButtonGroupSeparatorProps,
|
||||||
|
} from "./types";
|
||||||
|
|||||||
@@ -374,3 +374,21 @@ export type TabsIndicatorProps = InstanceType<typeof TabsIndicator>["$props"];
|
|||||||
|
|
||||||
import type TabsSeparator from "./components/tabs/TabsSeparator.vue";
|
import type TabsSeparator from "./components/tabs/TabsSeparator.vue";
|
||||||
export type TabsSeparatorProps = InstanceType<typeof TabsSeparator>["$props"];
|
export type TabsSeparatorProps = InstanceType<typeof TabsSeparator>["$props"];
|
||||||
|
|
||||||
|
import type ButtonGroup from "./components/button-group/ButtonGroup.vue";
|
||||||
|
import type ButtonGroupSeparator from "./components/button-group/ButtonGroupSeparator.vue";
|
||||||
|
import type ToggleButton from "./components/toggle-button/ToggleButton.vue";
|
||||||
|
import type ToggleButtonGroup from "./components/toggle-button-group/ToggleButtonGroup.vue";
|
||||||
|
import type ToggleButtonGroupSeparator from "./components/toggle-button-group/ToggleButtonGroupSeparator.vue";
|
||||||
|
|
||||||
|
export type ButtonGroupProps = InstanceType<typeof ButtonGroup>["$props"];
|
||||||
|
export type ButtonGroupSeparatorProps = InstanceType<
|
||||||
|
typeof ButtonGroupSeparator
|
||||||
|
>["$props"];
|
||||||
|
export type ToggleButtonProps = InstanceType<typeof ToggleButton>["$props"];
|
||||||
|
export type ToggleButtonGroupProps = InstanceType<
|
||||||
|
typeof ToggleButtonGroup
|
||||||
|
>["$props"];
|
||||||
|
export type ToggleButtonGroupSeparatorProps = InstanceType<
|
||||||
|
typeof ToggleButtonGroupSeparator
|
||||||
|
>["$props"];
|
||||||
|
|||||||
@@ -0,0 +1,865 @@
|
|||||||
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { mount } from "@vue/test-utils";
|
||||||
|
import { defineComponent, h, nextTick, ref } from "vue";
|
||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
ButtonGroup,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} from "../packages/vue/src";
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
function demoNames(page: string, prefix: string) {
|
||||||
|
const document = readFileSync(`apps/docs/components/${page}.md`, "utf8");
|
||||||
|
return [
|
||||||
|
...document.matchAll(
|
||||||
|
new RegExp(`<ComponentPreview name="${prefix}-([^"]+)"`, "g"),
|
||||||
|
),
|
||||||
|
].map((match) => match[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("ButtonGroup", () => {
|
||||||
|
it("renders with role=group and data-slot", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, () => [
|
||||||
|
h(Button, () => "One"),
|
||||||
|
h(Button, () => "Two"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const group = w.get('[role="group"]');
|
||||||
|
expect(group.attributes("data-slot")).toBe("button-group");
|
||||||
|
expect(group.classes().join(" ")).toContain("hv-button-group");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes orientation BEM modifiers", async () => {
|
||||||
|
const orientation = ref<"horizontal" | "vertical">("horizontal");
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, { orientation: orientation.value }, () => [
|
||||||
|
h(Button, () => "One"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(w.get('[role="group"]').classes().join(" ")).toContain(
|
||||||
|
"hv-button-group--horizontal",
|
||||||
|
);
|
||||||
|
orientation.value = "vertical";
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get('[role="group"]').classes().join(" ")).toContain(
|
||||||
|
"hv-button-group--vertical",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders Separator with data-slot", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, () => [
|
||||||
|
h(Button, () => "One"),
|
||||||
|
h(ButtonGroupSeparator),
|
||||||
|
h(Button, () => "Two"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const separator = w.get('[data-slot="button-group-separator"]');
|
||||||
|
expect(separator.attributes("aria-hidden")).toBe("true");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes inherited size and variant on direct Button children", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, { size: "sm", variant: "secondary" }, () => [
|
||||||
|
h(Button, () => "Save"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const button = w.get("button");
|
||||||
|
expect(button.classes().join(" ")).toContain("hv-button--sm");
|
||||||
|
expect(button.classes().join(" ")).toContain("hv-button--secondary");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes inherited isDisabled on direct Button children", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, { isDisabled: true }, () => [h(Button, () => "Save")]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect((w.get("button").element as HTMLButtonElement).disabled).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports child Button props overriding group defaults", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, { size: "sm", variant: "secondary" }, () => [
|
||||||
|
h(Button, { size: "lg", variant: "primary" }, () => "Override"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const classes = w.get("button").classes().join(" ");
|
||||||
|
expect(classes).toContain("hv-button--lg");
|
||||||
|
expect(classes).toContain("hv-button--primary");
|
||||||
|
expect(classes).not.toContain("hv-button--sm");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes no inherited context on nested non-direct Buttons", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, { size: "sm", variant: "secondary" }, () => [
|
||||||
|
h("div", [h(Button, () => "Nested")]),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const classes = w.get("button").classes().join(" ");
|
||||||
|
expect(classes).not.toContain("hv-button--sm");
|
||||||
|
expect(classes).not.toContain("hv-button--secondary");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports pressing grouped buttons once per click", async () => {
|
||||||
|
const onPress = vi.fn();
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, () => [
|
||||||
|
h(Button, { onClick: onPress }, () => "Save"),
|
||||||
|
h(Button, () => "Cancel"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await w.get("button").trigger("click");
|
||||||
|
expect(onPress).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ToggleButton", () => {
|
||||||
|
it("renders with role and accessible name", () => {
|
||||||
|
const w = mount(ToggleButton, { slots: { default: "Bold" } });
|
||||||
|
const button = w.get("button");
|
||||||
|
expect(button.text()).toBe("Bold");
|
||||||
|
expect(button.attributes("type")).toBe("button");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes BEM block, data-slot, and aria-pressed", () => {
|
||||||
|
const w = mount(ToggleButton, { slots: { default: "Bold" } });
|
||||||
|
const button = w.get("button");
|
||||||
|
expect(button.classes().join(" ")).toContain("hv-toggle-button");
|
||||||
|
expect(button.attributes("data-slot")).toBe("toggle-button");
|
||||||
|
expect(button.attributes("aria-pressed")).toBe("false");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports data attribute passthrough", () => {
|
||||||
|
const w = mount(ToggleButton, {
|
||||||
|
slots: { default: "Bold" },
|
||||||
|
attrs: { "data-testid": "toggle" },
|
||||||
|
});
|
||||||
|
expect(w.get('[data-testid="toggle"]').element).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports toggling selected state on click", async () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
const w = mount(ToggleButton, {
|
||||||
|
slots: { default: "Bold" },
|
||||||
|
props: { onChange },
|
||||||
|
});
|
||||||
|
const button = w.get("button");
|
||||||
|
await button.trigger("click");
|
||||||
|
expect(button.attributes("aria-pressed")).toBe("true");
|
||||||
|
expect(button.attributes("data-selected")).toBe("true");
|
||||||
|
expect(onChange).toHaveBeenCalledWith(true);
|
||||||
|
await button.trigger("click");
|
||||||
|
expect(button.attributes("aria-pressed")).toBe("false");
|
||||||
|
expect(onChange).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports uncontrolled defaultSelected", () => {
|
||||||
|
const w = mount(ToggleButton, {
|
||||||
|
slots: { default: "Bold" },
|
||||||
|
props: { defaultSelected: true },
|
||||||
|
});
|
||||||
|
expect(w.get("button").attributes("aria-pressed")).toBe("true");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports controlled isSelected without mutating parent value", async () => {
|
||||||
|
const selected = ref(false);
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
setup: () => () =>
|
||||||
|
h(
|
||||||
|
ToggleButton,
|
||||||
|
{
|
||||||
|
isSelected: selected.value,
|
||||||
|
"onUpdate:modelValue": (value: boolean) => {
|
||||||
|
selected.value = value;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
() => "Bold",
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await w.get("button").trigger("click");
|
||||||
|
expect(selected.value).toBe(true);
|
||||||
|
await w.setProps?.({});
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get("button").attributes("aria-pressed")).toBe("true");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports hover and press state hooks", async () => {
|
||||||
|
const w = mount(ToggleButton, { slots: { default: "Bold" } });
|
||||||
|
const button = w.get("button");
|
||||||
|
await button.trigger("pointerenter");
|
||||||
|
expect(button.attributes("data-hovered")).toBe("true");
|
||||||
|
await button.trigger("pointerleave");
|
||||||
|
expect(button.attributes("data-hovered")).toBeUndefined();
|
||||||
|
await button.trigger("pointerdown");
|
||||||
|
expect(button.attributes("data-pressed")).toBe("true");
|
||||||
|
await button.trigger("pointerup");
|
||||||
|
expect(button.attributes("data-pressed")).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports keyboard activation with Enter and Space", async () => {
|
||||||
|
const w = mount(ToggleButton, { slots: { default: "Bold" } });
|
||||||
|
const button = w.get("button");
|
||||||
|
button.element.focus();
|
||||||
|
await button.trigger("keydown", { key: "Enter" });
|
||||||
|
await button.trigger("click");
|
||||||
|
expect(button.attributes("aria-pressed")).toBe("true");
|
||||||
|
await button.trigger("keydown", { key: " " });
|
||||||
|
await button.trigger("click");
|
||||||
|
expect(button.attributes("aria-pressed")).toBe("false");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports disabled state and blocks toggle", async () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
const w = mount(ToggleButton, {
|
||||||
|
slots: { default: "Bold" },
|
||||||
|
props: { isDisabled: true, onChange },
|
||||||
|
});
|
||||||
|
const button = w.get("button");
|
||||||
|
expect((button.element as HTMLButtonElement).disabled).toBe(true);
|
||||||
|
expect(button.attributes("data-disabled")).toBe("true");
|
||||||
|
await button.trigger("click");
|
||||||
|
expect(onChange).not.toHaveBeenCalled();
|
||||||
|
expect(button.attributes("aria-pressed")).toBe("false");
|
||||||
|
await button.trigger("pointerenter");
|
||||||
|
expect(button.attributes("data-hovered")).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ToggleButtonGroup", () => {
|
||||||
|
it("exposes data-slot and BEM block", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ToggleButtonGroup, { selectionMode: "multiple" }, () => [
|
||||||
|
h(ToggleButton, { id: "bold" }, () => "Bold"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const group = w.get('[data-slot="toggle-button-group"]');
|
||||||
|
expect(group.classes().join(" ")).toContain("hv-toggle-button-group");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders a Separator with data-slot", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ToggleButtonGroup, { selectionMode: "multiple" }, () => [
|
||||||
|
h(ToggleButton, { id: "bold" }, () => "Bold"),
|
||||||
|
h(ToggleButton, { id: "italic" }, () => [
|
||||||
|
h(ToggleButtonGroupSeparator),
|
||||||
|
"Italic",
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const separator = w.get('[data-slot="toggle-button-group-separator"]');
|
||||||
|
expect(separator.attributes("aria-hidden")).toBe("true");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes orientation and full-width BEM modifiers", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{
|
||||||
|
selectionMode: "multiple",
|
||||||
|
orientation: "vertical",
|
||||||
|
fullWidth: true,
|
||||||
|
},
|
||||||
|
() => [h(ToggleButton, { id: "bold" }, () => "Bold")],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const classes = w
|
||||||
|
.get('[data-slot="toggle-button-group"]')
|
||||||
|
.classes()
|
||||||
|
.join(" ");
|
||||||
|
expect(classes).toContain("hv-toggle-button-group--vertical");
|
||||||
|
expect(classes).toContain("hv-toggle-button-group--full-width");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes detached BEM modifier", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{ selectionMode: "multiple", isDetached: true },
|
||||||
|
() => [h(ToggleButton, { id: "bold" }, () => "Bold")],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
w.get('[data-slot="toggle-button-group"]').classes().join(" "),
|
||||||
|
).toContain("hv-toggle-button-group--detached");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("selectionMode=multiple", () => {
|
||||||
|
it("exposes a toolbar role with pressable toggle buttons", async () => {
|
||||||
|
const onSelectionChange = vi.fn();
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{
|
||||||
|
selectionMode: "multiple",
|
||||||
|
onSelectionChange,
|
||||||
|
},
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { id: "bold" }, () => "Bold"),
|
||||||
|
h(ToggleButton, { id: "italic" }, () => "Italic"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const group = w.get('[role="toolbar"]');
|
||||||
|
expect(group.attributes("data-slot")).toBe("toggle-button-group");
|
||||||
|
const bold = w.findAll("button")[0]!;
|
||||||
|
expect(bold.attributes("aria-pressed")).toBe("false");
|
||||||
|
await bold.trigger("click");
|
||||||
|
expect(bold.attributes("aria-pressed")).toBe("true");
|
||||||
|
expect(onSelectionChange).toHaveBeenCalledWith(["bold"]);
|
||||||
|
await w.findAll("button")[1]!.trigger("click");
|
||||||
|
expect(onSelectionChange).toHaveBeenCalledWith(["bold", "italic"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports defaultSelectedKeys", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{
|
||||||
|
selectionMode: "multiple",
|
||||||
|
defaultSelectedKeys: ["bold"],
|
||||||
|
},
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { id: "bold" }, () => "Bold"),
|
||||||
|
h(ToggleButton, { id: "italic" }, () => "Italic"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const [bold, italic] = w.findAll("button");
|
||||||
|
expect(bold!.attributes("aria-pressed")).toBe("true");
|
||||||
|
expect(italic!.attributes("aria-pressed")).toBe("false");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("selectionMode=single", () => {
|
||||||
|
it("exposes a radiogroup role with radio-style buttons", async () => {
|
||||||
|
const onSelectionChange = vi.fn();
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{ selectionMode: "single", onSelectionChange },
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { id: "left" }, () => "Left"),
|
||||||
|
h(ToggleButton, { id: "center" }, () => "Center"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(w.get('[role="radiogroup"]').attributes("data-slot")).toBe(
|
||||||
|
"toggle-button-group",
|
||||||
|
);
|
||||||
|
const left = w.findAll("button")[0]!;
|
||||||
|
const center = w.findAll("button")[1]!;
|
||||||
|
expect(left.attributes("role")).toBe("radio");
|
||||||
|
expect(left.attributes("aria-checked")).toBe("false");
|
||||||
|
await left.trigger("click");
|
||||||
|
expect(left.attributes("aria-checked")).toBe("true");
|
||||||
|
expect(onSelectionChange).toHaveBeenCalledWith("left");
|
||||||
|
await center.trigger("click");
|
||||||
|
expect(center.attributes("aria-checked")).toBe("true");
|
||||||
|
expect(left.attributes("aria-checked")).toBe("false");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports disallowEmptySelection", async () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{
|
||||||
|
selectionMode: "single",
|
||||||
|
disallowEmptySelection: true,
|
||||||
|
defaultSelectedKeys: "left",
|
||||||
|
},
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { id: "left" }, () => "Left"),
|
||||||
|
h(ToggleButton, { id: "center" }, () => "Center"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const left = w.findAll("button")[0]!;
|
||||||
|
await left.trigger("click");
|
||||||
|
expect(left.attributes("aria-checked")).toBe("true");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not merge string and number keys with the same text", async () => {
|
||||||
|
const seen: unknown[] = [];
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{
|
||||||
|
selectionMode: "multiple",
|
||||||
|
onSelectionChange: (value: unknown) => seen.push(value),
|
||||||
|
},
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { id: 1 }, () => "One"),
|
||||||
|
h(ToggleButton, { id: "1" }, () => "One text"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await w.findAll("button")[0]!.trigger("click");
|
||||||
|
await w.findAll("button")[1]!.trigger("click");
|
||||||
|
expect(seen.at(-1)).toEqual([1, "1"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports group disabled state on every button", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{ selectionMode: "multiple", isDisabled: true },
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { id: "bold" }, () => "Bold"),
|
||||||
|
h(ToggleButton, { id: "italic" }, () => "Italic"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
for (const button of w.findAll("button")) {
|
||||||
|
expect((button.element as HTMLButtonElement).disabled).toBe(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes inherited size on child ToggleButtons", () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{ selectionMode: "multiple", size: "lg" },
|
||||||
|
() => [h(ToggleButton, { id: "bold" }, () => "Bold")],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(w.get("button").classes().join(" ")).toContain(
|
||||||
|
"hv-toggle-button--lg",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports dynamic members leaving the group", async () => {
|
||||||
|
const show = ref(true);
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
setup: () => () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{
|
||||||
|
selectionMode: "multiple",
|
||||||
|
defaultSelectedKeys: ["bold", "italic"],
|
||||||
|
},
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { id: "bold" }, () => "Bold"),
|
||||||
|
show.value
|
||||||
|
? h(ToggleButton, { id: "italic" }, () => "Italic")
|
||||||
|
: null,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(w.findAll("button")).toHaveLength(2);
|
||||||
|
show.value = false;
|
||||||
|
await nextTick();
|
||||||
|
expect(w.findAll("button")).toHaveLength(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ButtonGroup / ToggleButton demos", () => {
|
||||||
|
it("includes every preview in the pinned upstream documents", () => {
|
||||||
|
expect(demoNames("button-group", "button-group")).toEqual([
|
||||||
|
"basic",
|
||||||
|
"variants",
|
||||||
|
"sizes",
|
||||||
|
"orientation",
|
||||||
|
"with-icons",
|
||||||
|
"full-width",
|
||||||
|
"disabled",
|
||||||
|
"without-separator",
|
||||||
|
"custom-styles",
|
||||||
|
]);
|
||||||
|
expect(demoNames("toggle-button", "toggle-button")).toEqual([
|
||||||
|
"basic",
|
||||||
|
"variants",
|
||||||
|
"icon-only",
|
||||||
|
"sizes",
|
||||||
|
"disabled",
|
||||||
|
"controlled",
|
||||||
|
"custom-styles",
|
||||||
|
]);
|
||||||
|
expect(demoNames("toggle-button-group", "toggle-button-group")).toEqual([
|
||||||
|
"basic",
|
||||||
|
"sizes",
|
||||||
|
"orientation",
|
||||||
|
"full-width",
|
||||||
|
"disabled",
|
||||||
|
"without-separator",
|
||||||
|
"attached",
|
||||||
|
"selection-mode",
|
||||||
|
"controlled",
|
||||||
|
"custom-styles",
|
||||||
|
]);
|
||||||
|
for (const name of demoNames("button-group", "button-group"))
|
||||||
|
expect(
|
||||||
|
readFileSync(`apps/docs/demos/button-group-${name}.vue`, "utf8"),
|
||||||
|
).toContain("<template>");
|
||||||
|
for (const name of demoNames("toggle-button", "toggle-button"))
|
||||||
|
expect(
|
||||||
|
readFileSync(`apps/docs/demos/toggle-button-${name}.vue`, "utf8"),
|
||||||
|
).toContain("<template>");
|
||||||
|
for (const name of demoNames("toggle-button-group", "toggle-button-group"))
|
||||||
|
expect(
|
||||||
|
readFileSync(`apps/docs/demos/toggle-button-group-${name}.vue`, "utf8"),
|
||||||
|
).toContain("<template>");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ButtonGroup fullWidth inheritance", () => {
|
||||||
|
it("inherits fullWidth on direct children and keeps child override", () => {
|
||||||
|
const inherited = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, { fullWidth: true }, () => [h(Button, () => "Wide")]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(inherited.get("button").classes().join(" ")).toContain(
|
||||||
|
"hv-button--full-width",
|
||||||
|
);
|
||||||
|
const overridden = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ButtonGroup, { fullWidth: true }, () => [
|
||||||
|
h(Button, { fullWidth: false }, () => "Not wide"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(overridden.get("button").classes().join(" ")).not.toContain(
|
||||||
|
"hv-button--full-width",
|
||||||
|
);
|
||||||
|
const plain = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () => h(Button, () => "Plain"),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(plain.get("button").classes().join(" ")).not.toContain(
|
||||||
|
"hv-button--full-width",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("M26 review regressions beyond the probe file", () => {
|
||||||
|
it("RTL horizontal groups reverse arrow direction across three members", async () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{
|
||||||
|
selectionMode: "multiple",
|
||||||
|
dir: "rtl",
|
||||||
|
orientation: "horizontal",
|
||||||
|
},
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { value: "a" }, () => "A"),
|
||||||
|
h(ToggleButton, { value: "b" }, () => "B"),
|
||||||
|
h(ToggleButton, { value: "c" }, () => "C"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
await nextTick();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
// DOM order a,b,c. RTL ArrowLeft advances toward the end of the list.
|
||||||
|
(buttons[0].element as HTMLElement).focus();
|
||||||
|
await buttons[0].trigger("keydown", { key: "ArrowLeft" });
|
||||||
|
expect(document.activeElement).toBe(buttons[1].element);
|
||||||
|
await buttons[1].trigger("keydown", { key: "ArrowLeft" });
|
||||||
|
expect(document.activeElement).toBe(buttons[2].element);
|
||||||
|
await buttons[2].trigger("keydown", { key: "ArrowRight" });
|
||||||
|
expect(document.activeElement).toBe(buttons[1].element);
|
||||||
|
await buttons[1].trigger("keydown", { key: "ArrowRight" });
|
||||||
|
expect(document.activeElement).toBe(buttons[0].element);
|
||||||
|
w.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("controlled parent that rejects updates keeps the external value", async () => {
|
||||||
|
const selected = ref<string | number | null>("a");
|
||||||
|
const changes: unknown[] = [];
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
setup: () => () =>
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{
|
||||||
|
selectionMode: "single",
|
||||||
|
modelValue: selected.value,
|
||||||
|
"onUpdate:modelValue": (value: unknown) => {
|
||||||
|
changes.push(value);
|
||||||
|
// parent refuses to commit
|
||||||
|
},
|
||||||
|
},
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { value: "a" }, () => "A"),
|
||||||
|
h(ToggleButton, { value: "b" }, () => "B"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
await nextTick();
|
||||||
|
await w.findAll("button")[1]!.trigger("click");
|
||||||
|
expect(changes).toEqual(["b"]);
|
||||||
|
expect(w.findAll('[aria-checked="true"]')).toHaveLength(1);
|
||||||
|
expect(w.findAll("button")[0]!.attributes("aria-checked")).toBe("true");
|
||||||
|
w.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("child size override then reset restores inherited group size", async () => {
|
||||||
|
const size = ref<"sm" | "lg">("sm");
|
||||||
|
const override = ref(true);
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
setup: () => () =>
|
||||||
|
h(ToggleButtonGroup, { size: size.value }, () => [
|
||||||
|
h(
|
||||||
|
ToggleButton,
|
||||||
|
{
|
||||||
|
value: "a",
|
||||||
|
size: override.value ? ("lg" as const) : undefined,
|
||||||
|
},
|
||||||
|
() => "A",
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
expect(w.get("button").classes()).toContain("hv-toggle-button--lg");
|
||||||
|
override.value = false;
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get("button").classes()).toContain("hv-toggle-button--sm");
|
||||||
|
size.value = "lg";
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get("button").classes()).toContain("hv-toggle-button--lg");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("arrow navigation follows keyed DOM order after a reorder", async () => {
|
||||||
|
const keys = ref(["a", "b", "c"]);
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
setup: () => () =>
|
||||||
|
h(ToggleButtonGroup, { selectionMode: "multiple" }, () =>
|
||||||
|
keys.value.map((key) =>
|
||||||
|
h(ToggleButton, { key, value: key }, () => key),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
await nextTick();
|
||||||
|
keys.value = ["c", "b", "a"];
|
||||||
|
await nextTick();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
expect(buttons.map((b) => b.text())).toEqual(["c", "b", "a"]);
|
||||||
|
(buttons[1]!.element as HTMLElement).focus();
|
||||||
|
await buttons[1]!.trigger("keydown", { key: "ArrowRight" });
|
||||||
|
expect(document.activeElement).toBe(buttons[2]!.element);
|
||||||
|
await buttons[2]!.trigger("keydown", { key: "ArrowRight" });
|
||||||
|
expect(document.activeElement).toBe(buttons[0]!.element);
|
||||||
|
await buttons[0]!.trigger("keydown", { key: "End" });
|
||||||
|
expect(document.activeElement).toBe(buttons[2]!.element);
|
||||||
|
await buttons[2]!.trigger("keydown", { key: "Home" });
|
||||||
|
expect(document.activeElement).toBe(buttons[0]!.element);
|
||||||
|
w.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("real focus moves the single Tab entry to that member", async () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ToggleButtonGroup, { selectionMode: "multiple" }, () => [
|
||||||
|
h(ToggleButton, { value: "a" }, () => "A"),
|
||||||
|
h(ToggleButton, { value: "b" }, () => "B"),
|
||||||
|
h(ToggleButton, { value: "c" }, () => "C"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
await nextTick();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
expect(buttons[0]!.attributes("tabindex")).toBe("0");
|
||||||
|
(buttons[2]!.element as HTMLElement).focus();
|
||||||
|
await nextTick();
|
||||||
|
expect(buttons[2]!.attributes("tabindex")).toBe("0");
|
||||||
|
expect(buttons[0]!.attributes("tabindex")).toBe("-1");
|
||||||
|
expect(
|
||||||
|
buttons.filter((b) => b.attributes("tabindex") === "0"),
|
||||||
|
).toHaveLength(1);
|
||||||
|
w.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removing the active member promotes a new tab stop", async () => {
|
||||||
|
const show = ref(true);
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
setup: () => () =>
|
||||||
|
h(ToggleButtonGroup, { selectionMode: "multiple" }, () => [
|
||||||
|
show.value ? h(ToggleButton, { value: "a" }, () => "A") : null,
|
||||||
|
h(ToggleButton, { value: "b" }, () => "B"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
await nextTick();
|
||||||
|
expect(w.findAll("button")[0]!.attributes("tabindex")).toBe("0");
|
||||||
|
show.value = false;
|
||||||
|
await nextTick();
|
||||||
|
const rest = w.findAll("button");
|
||||||
|
expect(rest).toHaveLength(1);
|
||||||
|
expect(rest[0]!.attributes("tabindex")).toBe("0");
|
||||||
|
w.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Home and End jump to the group edges", async () => {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
render: () =>
|
||||||
|
h(ToggleButtonGroup, { selectionMode: "multiple" }, () => [
|
||||||
|
h(ToggleButton, { value: "a" }, () => "A"),
|
||||||
|
h(ToggleButton, { value: "b" }, () => "B"),
|
||||||
|
h(ToggleButton, { value: "c" }, () => "C"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
await nextTick();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
(buttons[1]!.element as HTMLElement).focus();
|
||||||
|
await buttons[1]!.trigger("keydown", { key: "End" });
|
||||||
|
expect(document.activeElement).toBe(buttons[2]!.element);
|
||||||
|
await buttons[2]!.trigger("keydown", { key: "Home" });
|
||||||
|
expect(document.activeElement).toBe(buttons[0]!.element);
|
||||||
|
w.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("standalone buttons keep user-supplied DOM ids", () => {
|
||||||
|
const w = mount(ToggleButton, {
|
||||||
|
props: { id: "like-button" },
|
||||||
|
slots: { default: "Like" },
|
||||||
|
});
|
||||||
|
expect(w.get("button").attributes("id")).toBe("like-button");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const buttonGroupDemos = [
|
||||||
|
"basic",
|
||||||
|
"variants",
|
||||||
|
"sizes",
|
||||||
|
"orientation",
|
||||||
|
"with-icons",
|
||||||
|
"full-width",
|
||||||
|
"disabled",
|
||||||
|
"without-separator",
|
||||||
|
"custom-styles",
|
||||||
|
];
|
||||||
|
const toggleButtonDemos = [
|
||||||
|
"basic",
|
||||||
|
"variants",
|
||||||
|
"icon-only",
|
||||||
|
"sizes",
|
||||||
|
"disabled",
|
||||||
|
"controlled",
|
||||||
|
"custom-styles",
|
||||||
|
];
|
||||||
|
const toggleGroupDemos = [
|
||||||
|
"basic",
|
||||||
|
"sizes",
|
||||||
|
"orientation",
|
||||||
|
"full-width",
|
||||||
|
"disabled",
|
||||||
|
"without-separator",
|
||||||
|
"attached",
|
||||||
|
"selection-mode",
|
||||||
|
"controlled",
|
||||||
|
"custom-styles",
|
||||||
|
];
|
||||||
|
|
||||||
|
describe("M26 demos compile and mount without Vue warnings", () => {
|
||||||
|
it("mounts all 26 baseline demos", async () => {
|
||||||
|
const warnings: string[] = [];
|
||||||
|
const spy = vi.spyOn(console, "warn").mockImplementation((...args) => {
|
||||||
|
warnings.push(args.map(String).join(" "));
|
||||||
|
});
|
||||||
|
const files = [
|
||||||
|
...buttonGroupDemos.map((n) => `button-group-${n}`),
|
||||||
|
...toggleButtonDemos.map((n) => `toggle-button-${n}`),
|
||||||
|
...toggleGroupDemos.map((n) => `toggle-button-group-${n}`),
|
||||||
|
];
|
||||||
|
expect(files).toHaveLength(26);
|
||||||
|
for (const name of files) {
|
||||||
|
const mod = await import(`../apps/docs/demos/${name}.vue`);
|
||||||
|
const w = mount(mod.default, { attachTo: document.body });
|
||||||
|
await nextTick();
|
||||||
|
expect(w.html().length).toBeGreaterThan(0);
|
||||||
|
w.unmount();
|
||||||
|
}
|
||||||
|
spy.mockRestore();
|
||||||
|
expect(warnings).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import { afterEach, expect, it, vi } from "vitest";
|
||||||
|
import { mount, flushPromises } from "@vue/test-utils";
|
||||||
|
import { defineComponent, ref, nextTick } from "vue";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
ButtonGroup,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroup,
|
||||||
|
} from "../packages/vue/src";
|
||||||
|
const wrappers: ReturnType<typeof mount>[] = [];
|
||||||
|
afterEach(async () => {
|
||||||
|
wrappers.splice(0).forEach((w) => w.unmount());
|
||||||
|
await flushPromises();
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
});
|
||||||
|
function fixture(template: string, setup = () => ({})) {
|
||||||
|
const w = mount(
|
||||||
|
defineComponent({
|
||||||
|
components: { Button, ButtonGroup, ToggleButton, ToggleButtonGroup },
|
||||||
|
template,
|
||||||
|
setup,
|
||||||
|
}),
|
||||||
|
{ attachTo: document.body },
|
||||||
|
);
|
||||||
|
wrappers.push(w);
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
it("caller preventDefault cancels standalone and grouped activation", async () => {
|
||||||
|
const change = vi.fn();
|
||||||
|
const w = fixture(
|
||||||
|
'<div><ToggleButton @click.prevent @change="change">one</ToggleButton><ToggleButtonGroup selection-mode="multiple" @selection-change="change"><ToggleButton value="a" @click.prevent>two</ToggleButton></ToggleButtonGroup></div>',
|
||||||
|
() => ({ change }),
|
||||||
|
);
|
||||||
|
for (const b of w.findAll("button")) await b.trigger("click");
|
||||||
|
expect(change).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
it("dynamic group size updates existing members", async () => {
|
||||||
|
const size = ref("sm");
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup :size="size"><ToggleButton value="a">A</ToggleButton></ToggleButtonGroup>',
|
||||||
|
() => ({ size }),
|
||||||
|
);
|
||||||
|
expect(w.get("button").classes()).toContain("hv-toggle-button--sm");
|
||||||
|
size.value = "lg";
|
||||||
|
await nextTick();
|
||||||
|
expect(w.get("button").classes()).toContain("hv-toggle-button--lg");
|
||||||
|
});
|
||||||
|
it("multiple to single reconciles to at most one checked radio", async () => {
|
||||||
|
const mode = ref("multiple");
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup :selection-mode="mode" :default-selected-keys="[\'a\',\'b\']"><ToggleButton value="a">A</ToggleButton><ToggleButton value="b">B</ToggleButton></ToggleButtonGroup>',
|
||||||
|
() => ({ mode }),
|
||||||
|
);
|
||||||
|
mode.value = "single";
|
||||||
|
await nextTick();
|
||||||
|
expect(w.findAll('[aria-checked="true"]').length).toBeLessThanOrEqual(1);
|
||||||
|
});
|
||||||
|
it("a disabled first member leaves an enabled keyboard entry point", async () => {
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup><ToggleButton value="a" is-disabled>A</ToggleButton><ToggleButton value="b">B</ToggleButton></ToggleButtonGroup>',
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
expect(w.findAll("button")[1].attributes("tabindex")).toBe("0");
|
||||||
|
});
|
||||||
|
it("numeric and string group keys do not produce duplicate DOM ids", () => {
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup selection-mode="multiple"><ToggleButton :id="1">number</ToggleButton><ToggleButton id="1">string</ToggleButton></ToggleButtonGroup>',
|
||||||
|
);
|
||||||
|
const ids = w
|
||||||
|
.findAll("button")
|
||||||
|
.map((b) => b.attributes("id"))
|
||||||
|
.filter((id) => id !== undefined);
|
||||||
|
expect(new Set(ids).size).toBe(ids.length);
|
||||||
|
});
|
||||||
|
it("cancelled arrow key is not processed", async () => {
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup><ToggleButton value="a" @keydown.prevent>A</ToggleButton><ToggleButton value="b">B</ToggleButton></ToggleButtonGroup>',
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
(buttons[0].element as HTMLElement).focus();
|
||||||
|
await buttons[0].trigger("keydown", { key: "ArrowRight" });
|
||||||
|
expect(document.activeElement).toBe(buttons[0].element);
|
||||||
|
});
|
||||||
|
it("changing member keys updates keyboard registration", async () => {
|
||||||
|
const key = ref("a");
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup><ToggleButton :value="key">first</ToggleButton><ToggleButton value="b">second</ToggleButton></ToggleButtonGroup>',
|
||||||
|
() => ({ key }),
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
key.value = "c";
|
||||||
|
await nextTick();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
(buttons[0].element as HTMLElement).focus();
|
||||||
|
await buttons[0].trigger("keydown", { key: "ArrowRight" });
|
||||||
|
expect(document.activeElement).toBe(buttons[1].element);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Tab exits the group using either a single tab stop or focus-to-end strategy", async () => {
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup><ToggleButton value="a">A</ToggleButton><ToggleButton value="b">B</ToggleButton><ToggleButton value="c">C</ToggleButton></ToggleButtonGroup>',
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
(buttons[0].element as HTMLElement).focus();
|
||||||
|
if (w.findAll('button[tabindex="0"]').length > 1) {
|
||||||
|
await buttons[0].trigger("keydown", { key: "Tab" });
|
||||||
|
expect(document.activeElement).toBe(buttons[2].element);
|
||||||
|
} else {
|
||||||
|
expect(w.findAll('button[tabindex="0"]')).toHaveLength(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("vertical orientation does not consume perpendicular arrows", async () => {
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup orientation="vertical"><ToggleButton value="a">A</ToggleButton><ToggleButton value="b">B</ToggleButton></ToggleButtonGroup>',
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
const first = w.findAll("button")[0];
|
||||||
|
(first.element as HTMLElement).focus();
|
||||||
|
await first.trigger("keydown", { key: "ArrowRight" });
|
||||||
|
expect(document.activeElement).toBe(first.element);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("explicit child isDisabled=false overrides only ButtonGroup default as in pinned source", () => {
|
||||||
|
const w = fixture(
|
||||||
|
'<ButtonGroup is-disabled><Button :is-disabled="false">Enabled override</Button></ButtonGroup>',
|
||||||
|
);
|
||||||
|
expect((w.get("button").element as HTMLButtonElement).disabled).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("arrow navigation follows keyed DOM order after a reorder", async () => {
|
||||||
|
const keys = ref(["a", "b", "c"]);
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup><ToggleButton v-for="key in keys" :key="key" :value="key">{{ key }}</ToggleButton></ToggleButtonGroup>',
|
||||||
|
() => ({ keys }),
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
keys.value = ["c", "b", "a"];
|
||||||
|
await nextTick();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
expect(buttons.map((b) => b.text())).toEqual(["c", "b", "a"]);
|
||||||
|
(buttons[1].element as HTMLElement).focus();
|
||||||
|
await buttons[1].trigger("keydown", { key: "ArrowRight" });
|
||||||
|
expect(document.activeElement).toBe(buttons[2].element);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("focusing a member updates the single Tab entry to that member", async () => {
|
||||||
|
const w = fixture(
|
||||||
|
'<ToggleButtonGroup><ToggleButton value="a">A</ToggleButton><ToggleButton value="b">B</ToggleButton><ToggleButton value="c">C</ToggleButton></ToggleButtonGroup>',
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
const buttons = w.findAll("button");
|
||||||
|
(buttons[2].element as HTMLElement).focus();
|
||||||
|
await nextTick();
|
||||||
|
expect(buttons[2].attributes("tabindex")).toBe("0");
|
||||||
|
expect(buttons[0].attributes("tabindex")).toBe("-1");
|
||||||
|
});
|
||||||
@@ -459,3 +459,74 @@ it("renders ScrollShadow and Tabs without browser globals and resolves initial p
|
|||||||
expect(controls).toBeTruthy();
|
expect(controls).toBeTruthy();
|
||||||
expect(html).toContain(`id="${controls}"`);
|
expect(html).toContain(`id="${controls}"`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("renders ButtonGroup and Toggle families without browser globals", async () => {
|
||||||
|
const {
|
||||||
|
Button,
|
||||||
|
ButtonGroup,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
} = await import("../packages/vue/src");
|
||||||
|
const html = await renderToString(
|
||||||
|
createSSRApp({
|
||||||
|
render: () => [
|
||||||
|
h(ButtonGroup, { size: "sm", variant: "secondary" }, () => [
|
||||||
|
h(Button, () => "First"),
|
||||||
|
h(Button, () => [h(ButtonGroupSeparator), "Second"]),
|
||||||
|
]),
|
||||||
|
h(ToggleButton, { defaultSelected: true }, () => "Like"),
|
||||||
|
h(
|
||||||
|
ToggleButtonGroup,
|
||||||
|
{ selectionMode: "multiple", defaultSelectedKeys: ["bold"] },
|
||||||
|
() => [
|
||||||
|
h(ToggleButton, { id: "bold" }, () => "Bold"),
|
||||||
|
h(ToggleButton, { id: "italic" }, () => [
|
||||||
|
h(ToggleButtonGroupSeparator),
|
||||||
|
"Italic",
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(html).toContain('data-slot="button-group"');
|
||||||
|
expect(html).toContain("hv-button--sm");
|
||||||
|
expect(html).toContain("hv-button--secondary");
|
||||||
|
expect(html).toContain('data-slot="button-group-separator"');
|
||||||
|
expect(html).toContain('aria-pressed="true"');
|
||||||
|
expect(html).toContain('data-slot="toggle-button-group"');
|
||||||
|
expect(html).toContain('role="toolbar"');
|
||||||
|
expect(html).toContain('data-selected="true"');
|
||||||
|
expect(html).toContain('data-slot="toggle-button-group-separator"');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps ToggleButton group keys out of DOM ids on the server", async () => {
|
||||||
|
const { ToggleButton, ToggleButtonGroup } =
|
||||||
|
await import("../packages/vue/src");
|
||||||
|
const html = await renderToString(
|
||||||
|
createSSRApp({
|
||||||
|
render: () =>
|
||||||
|
h(ToggleButtonGroup, { selectionMode: "multiple" }, () => [
|
||||||
|
h(ToggleButton, { id: 1 }, () => "number"),
|
||||||
|
h(ToggleButton, { id: "1" }, () => "string"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(html).not.toMatch(/id="1"/);
|
||||||
|
expect(html).toContain("number");
|
||||||
|
expect(html).toContain("string");
|
||||||
|
const ids = [...html.matchAll(/id="([^"]+)"/g)].map((m) => m[1]);
|
||||||
|
expect(new Set(ids).size).toBe(ids.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps standalone ToggleButton DOM ids stable on the server", async () => {
|
||||||
|
const { ToggleButton } = await import("../packages/vue/src");
|
||||||
|
const html = await renderToString(
|
||||||
|
createSSRApp({
|
||||||
|
render: () => h(ToggleButton, { id: "like-toggle" }, () => "Like"),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(html).toContain('id="like-toggle"');
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import {
|
||||||
|
ButtonGroup,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
type ButtonGroupProps,
|
||||||
|
type ToggleButtonGroupKey,
|
||||||
|
type ToggleButtonGroupProps,
|
||||||
|
type ToggleButtonProps,
|
||||||
|
} from "../../packages/vue/src";
|
||||||
|
|
||||||
|
// Compile-only public contract checks (not mounted or executed by Vitest).
|
||||||
|
function buttonToggleContract() {
|
||||||
|
const group: ButtonGroupProps = {
|
||||||
|
size: "sm",
|
||||||
|
variant: "secondary",
|
||||||
|
orientation: "vertical",
|
||||||
|
fullWidth: true,
|
||||||
|
isDisabled: true,
|
||||||
|
};
|
||||||
|
// @ts-expect-error unsupported size
|
||||||
|
const badSize: ButtonGroupProps = { size: "xl" };
|
||||||
|
// @ts-expect-error unsupported variant
|
||||||
|
const badVariant: ButtonGroupProps = { variant: "rainbow" };
|
||||||
|
|
||||||
|
const toggle: ToggleButtonProps = {
|
||||||
|
modelValue: true,
|
||||||
|
isSelected: false,
|
||||||
|
defaultValue: true,
|
||||||
|
defaultSelected: false,
|
||||||
|
isDisabled: true,
|
||||||
|
isIconOnly: true,
|
||||||
|
size: "lg",
|
||||||
|
variant: "ghost",
|
||||||
|
id: "bold",
|
||||||
|
value: 2,
|
||||||
|
};
|
||||||
|
// @ts-expect-error unsupported variant
|
||||||
|
const badToggleVariant: ToggleButtonProps = { variant: "outline" };
|
||||||
|
|
||||||
|
const selected: ToggleButtonGroupKey = "bold";
|
||||||
|
const numeric: ToggleButtonGroupKey = 3;
|
||||||
|
const toggleGroup: ToggleButtonGroupProps = {
|
||||||
|
selectionMode: "multiple",
|
||||||
|
modelValue: [selected, numeric],
|
||||||
|
defaultSelectedKeys: ["italic"],
|
||||||
|
disallowEmptySelection: true,
|
||||||
|
orientation: "horizontal",
|
||||||
|
size: "md",
|
||||||
|
isDetached: true,
|
||||||
|
fullWidth: true,
|
||||||
|
isDisabled: false,
|
||||||
|
};
|
||||||
|
// @ts-expect-error unsupported selection mode
|
||||||
|
const badMode: ToggleButtonGroupProps = { selectionMode: "all" };
|
||||||
|
|
||||||
|
return {
|
||||||
|
badMode,
|
||||||
|
badSize,
|
||||||
|
badToggleVariant,
|
||||||
|
badVariant,
|
||||||
|
group,
|
||||||
|
toggle,
|
||||||
|
toggleGroup,
|
||||||
|
ButtonGroup,
|
||||||
|
ButtonGroupSeparator,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroup,
|
||||||
|
ToggleButtonGroupSeparator,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
void buttonToggleContract;
|
||||||
Reference in New Issue
Block a user