fix: align Dropdown/Menu with the HeroUI baseline after fidelity audit

- menu-item.css keys disabled styling off the presence attribute Reka emits.
- Dropdown surfaces drive the ported enter/exit animations and use data-side
  for placement-specific motion.
- One role=menu per popup; items render their key as DOM id; submenu surfaces
  point aria-labelledby at the real trigger; MenuSection names its group from a
  nested Header.
- Custom (asChild) triggers stay keyboard focusable; library Button/Avatar keep
  their own layout instead of the custom-trigger rules.
- Items emit data-focused/data-hovered/data-pressed, expose the upstream render
  props to slots, and merge caller classes through tailwind-variants.
- Submenu triggers declare hasSubmenu explicitly and forward class/ARIA; the
  default submenu indicator uses the baseline chevron artwork.
- Demos restore Kbd slot="keyboard" (27x), IconSquarePlus, and remove the added
  comment, stray space and duplicated indicator SVGs.
- Document the page after the official structure and API tables, including
  renamed props, Vue extensions and remaining gaps.
This commit is contained in:
maoyingjie
2026-10-24 22:14:10 +08:00
parent 64aaf5e53f
commit 043a5418f3
27 changed files with 1124 additions and 254 deletions
+16
View File
@@ -925,3 +925,19 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
- 独立 tarball `/tmp/heroui-b01-consumer` 重新打包安装后:ESM 命名导出 + `@heroui-vue/styles/css` 通过;`b01-menu-dropdown-contract.ts` 在 bundler 与 NodeNext 下正反例均通过(`@ts-expect-error` 仍生效)。
- 浏览器 5181 实测(真实点击/真实按键):长按示例真实短点击后 `aria-expanded=false`、无 popover;真实 Enter 打开并保持、`aria-expanded=true`;Space 一次开一次关;Esc 关闭后焦点回到「长按」触发器。`with-submenus` 中焦点在子菜单项 WhatsApp 上按 Esc:子菜单卸载、根菜单仍开(`aria-expanded=true`)、焦点回「其他」;再按 Esc 关根菜单、焦点回「分享」。指针打开子菜单、焦点留在「其他」时同样只关一层。期间 console warn/error 为 0。
- 本运行时浏览器后端不提供 press-and-hold 输入,因此“按住达到阈值才打开”的计时路径只有 jsdom + 假时钟证据;真实鼠标长按与物理触屏仍未验证。完整读屏、Nuxt、逐像素、自动视觉对比也未验证。
### B01 忠实度审计与修复(同日)
按 [忠实度审计](migrations/B01-fidelity-audit.md) 对照官方 `dropdown.mdx` 与 17 个官方演示,逐项修掉复刻偏差,并重写文档页。
- **禁用项样式**:`menu-item.css` 的 `[data-disabled="true"]` 改为存在选择器(Reka 写空串,原选择器永不命中)。浏览器实测禁用行 `opacity 0.5`、`cursor not-allowed`,其余行 `opacity 1`。
- **进入/退出动画**:Dropdown 内容接入共享 `useOverlayAnimation`,输出 `data-entering`/`data-exiting`,CSS 的 `[data-placement]` 改为 Reka 实际输出的 `[data-side]`。浏览器实测打开 `data-entering="true"` + `animation: enter .15s`,结束后属性清除、`opacity 1`;关闭 `data-exiting="true"` + `animation: exit .1s` + `pointer-events:none`,随后卸载。
- **ARIA 结构**:每个弹层只剩 1 个 `role="menu"`(原为 2 个嵌套);条目渲染 DOM `id`;子菜单面板的 `aria-labelledby` 由悬空改为指向真实触发器;`MenuSection` 的 `Header` 通过注册成为分组可访问名称。
- **触发器**:加入 `.hv-dropdown__trigger.hv-button{display:inline-flex}` 与 `.hv-avatar{display:flex}` 兼容规则,纯图标触发器图标中心偏移由 `-12px` 修正为 `0`;自定义(Avatar)触发器补 `role="button"`/`tabindex="0"`,浏览器实测为 `<span role=button tabindex=0>` 且 Enter 可打开(官方渲染的是 `<button>`,DOM 仍不同)。
- **交互状态**:条目输出 `data-focused`/`data-hovered`/`data-pressed`;`custom-styles` 演示的 `data-[focused=true]:bg-default` 实测生效(键盘聚焦行背景为 `bg-default`)。条目与指示器插槽提供官方 Render Props(`isSelected/isFocused/isDisabled/isPressed` 与 `isIndeterminate`)。
- **子菜单**:`hasSubmenu` 改由 `DropdownSubmenuTrigger` 显式下发,不再依赖是否渲染指示器;子菜单面板与触发条目补上原本被丢弃的 `class`/ARIA。
- **样式合并**:用户 class 改经 tailwind-variants(含 twMerge)合并。
- **演示**:6 个演示共 27 处 `Kbd slot="keyboard"` 还原;`SquarePlus`→`IconSquarePlus`;`controlled-open-state` 多余空格、自定义指示器 5 段重复 SVG、长按演示自加注释。
- **文档**:`apps/docs/components/dropdown.md` 按官方分节重写(完整骨架、官方 4 类全局 CSS 示例、分节样式参考、每部件 API 表含改名列与 Vue 扩展、Render Props 表、官方无障碍条目、3 项相关组件)。
- **回归**:`tests/b01-menu-dropdown.test.ts` 增至 **27/27**(新增 17 个预览整体挂载无 warn/error、DOM id 与单 `role=menu`、禁用选择器、子菜单 `aria-labelledby` 可解析、Section 标签、自定义触发器可聚焦、插槽 render state、class 合并、无指示器子菜单),`b01-review.probe.test.ts` **7/7**;完整 **71 文件 / 897 项**;typecheck、build:docs、Prettier 通过。
- **仍保留**:链接型菜单项(`href`)不支持(Reka 无锚点路径)、子菜单悬停延迟固定 100ms、`disallowEmptySelection` 等官方 props 未提供、`DropdownRoot` 保留一层包裹元素;`Kbd slot="keyboard"` 之外未做逐像素对比,完整读屏/触屏/Nuxt 仍未验证。