fix: menu selection ARIA, cancelable activation, submenu and long-press

- Selected items use menuitemradio/menuitemcheckbox + aria-checked + data-selected
- onClick preventDefault cancels action/selection/close (user handlers first)
- Submenu trigger is a single menuitem (asChild); standalone Menu owns Reka root
- DropdownRoot trigger=longPress with threshold, keyboard fallback, cleanup
- Export *Props types; independent tarball ESM/CSS + NodeNext/bundler contracts
- Esc still closes the full submenu stack (recorded gap)
This commit is contained in:
maoyingjie
2026-10-24 21:19:04 +08:00
parent 06ddb6662a
commit 1692c6b0ac
16 changed files with 719 additions and 141 deletions
+23 -16
View File
@@ -160,13 +160,17 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
### DropdownRoot
| Prop | 类型 | 默认值 | 描述 |
| ------------- | ---------------- | ------ | -------------- |
| `open` | `boolean` | — | 受控展开 |
| `defaultOpen` | `boolean` | — | 非受控初始展开 |
| `modal` | `boolean` | `true` | 模态焦点管理 |
| `dir` | `'ltr' \| 'rtl'` | — | 文本方向 |
| `update:open` | 事件 | — | 展开变更 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------- | ------------------------ | --------- | ------------------------------- |
| `open` | `boolean` | — | 受控展开 |
| `defaultOpen` | `boolean` | — | 非受控初始展开 |
| `modal` | `boolean` | `true` | 模态焦点管理 |
| `dir` | `'ltr' \| 'rtl'` | — | 文本方向 |
| `trigger` | `'press' \| 'longPress'` | `'press'` | 长按打开并抑制随后 click |
| `longPressDuration` | `number` | `500` | 长按时长 ms;移动超过 10px 取消 |
| `update:open` | 事件 | — | 展开变更 |
长按模式下 Enter/Space 仍可键盘打开;`pointerup`/`pointercancel`/`pointerleave`/卸载会清理计时。
### DropdownTrigger
@@ -199,13 +203,16 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
### DropdownItem
| Prop | 类型 | 默认值 | 描述 |
| ------------ | ----------------------- | ----------- | -------------- |
| `id` | `MenuKey` | — | 条目标识 |
| `textValue` | `string` | — | 首字母导航文本 |
| `variant` | `'default' \| 'danger'` | `'default'` | 视觉变体 |
| `isDisabled` | `boolean` | `false` | 禁用 |
| `select` | 事件 `(key: MenuKey)` | — | 激活回调 |
| Prop | 类型 | 默认值 | 描述 |
| --------------- | ----------------------- | ----------- | ---------------------------- |
| `id` | `MenuKey` | — | 条目标识 |
| `textValue` | `string` | — | 首字母导航文本 |
| `variant` | `'default' \| 'danger'` | `'default'` | 视觉变体 |
| `isDisabled` | `boolean` | `false` | 禁用 |
| `closeOnSelect` | `boolean` | — | `false` 时动作后保持菜单打开 |
| `select` | 事件 `(key: MenuKey)` | — | 激活回调 |
**事件取消**:条目上 `@click.prevent`(或 `preventDefault`)会取消默认动作、选择变更与关闭。选择项输出 `menuitemradio`/`menuitemcheckbox` 并带 `aria-checked`;`selectionMode=none` 为 `menuitem`。
### DropdownItemIndicator
@@ -224,9 +231,9 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
## 上游差异
- React 对象部件改具名导出;`Selection`/`Set` 改 `MenuKey[]`;`onAction`/`onSelectionChange` 改 Vue 事件。
- 条目 `onClick` `preventDefault` 取消动作/选择/关闭(对应上游可取消事件契约)。
- 长按封装在 `DropdownRoot` `trigger="longPress"`;Menu/Item/Section 导出含 `*Props` 类型。
- `Kbd slot="keyboard"` 为上游原生 slot 透传;本库 Kbd 支持同结构。
- Menu/Item/Section 无独立官方文档页,契约折叠于 Dropdown 页;本库提供同名导出供组合。
- 长按触发由 Reka `DropdownMenuRoot` 的 trigger 策略提供;与上游 `trigger="longPress"` 对应关系见演示。
## 相关组件