Skip to content

[Bug]: 子菜单打开后在同一触发项内移动鼠标会意外关闭 #2929

Closed

Description

@qqqqqf-q

Environment

  • macOS 27.0,Node 25.6.1,pnpm 10.13.1
  • Reka UI 2.10.4;另在 v2 分支的 0a81bffcfbd29b9420cdad7b2cae58f8c1ced536 构建上复现
  • Vue 3.5.17,Chromium 152
  • 独立 Vue/Vite 项目,无 Nuxt、CSS 框架或动画

Link to minimal reproduction

独立复现源码与运行说明

git clone --depth 1 --branch repro-menu-focus https://github.com/qqqqqf-q/reka-ui.git
cd reka-ui/playground/menu-focus-repro
npm ci
npm run dev

复现通过 npm 安装未修改的 reka-ui@2.10.4,使用文档中的 Root / Portal / Content / Sub / SubTrigger / Portal / SubContent 组合。没有接管 open 状态或覆盖事件处理。

Steps to reproduce

  1. 点击 Open menu。
  2. 将鼠标移到 More →,等待右侧子菜单打开。
  3. 在 More → 内再移动几像素,不离开该触发项。

也可以在第 2 步后,缓慢地将鼠标移向右侧 Child two。

Describe the bug

子菜单会关闭;继续移动鼠标时可能重新打开,表现为闪烁。可以观察触发项的 aria-expanded 从 true 变成 false,因此这里发生了实际的关闭状态变化。

Expected behavior

鼠标仍在当前子菜单触发项内移动时,已经打开的子菜单应保持打开。

验证与拟议修复

在 Chromium 中使用 Playwright 的鼠标输入进行对照,并通过只读 MutationObserver 记录 aria-expanded 变化。两种鼠标路径各重复 5 次:

版本 触发项内移动时关闭 移向子菜单时关闭
npm 2.10.4 5/5 5/5
上述 v2 commit 5/5 5/5
相同 v2 commit,仅提前保存焦点事件目标 0/5 0/5

MenuItemImpl 的 pointermove 处理会调用元素的 .focus()。在这个程序触发的 focus 路径中,异步 focus 处理器恢复时,事件分发已经结束,event.currentTarget 为 null,因而覆盖了刚设置的 highlightedElement。

我会提交一个配套 PR,在 await nextTick() 前保存焦点目标,同时保留原有的异步处理、defaultPrevented 和 disabled 判断。新增回归测试复用仓库现有的 MenuWithSubmenu fixture:上游原代码在第二次 pointermove 后得到 aria-expanded="false",单点修复后保持 true。

以上结果来自 Chromium 自动化,尚未完成人类 QA 或其他浏览器验证;结论限于上述可复现路径。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions