Skip to content

fix: close submenus on root Escape - #893

Open
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/close-submenus-on-root-escape
Open

fix: close submenus on root Escape#893
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/close-submenus-on-root-escape

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 28, 2026

Copy link
Copy Markdown

Summary

  • close popup submenus when Escape is pressed while the root menu itself has focus
  • preserve inline-menu behavior and the existing item-focused parent navigation
  • cover the click-triggered submenu regression reported in Ant Design

Fixes ant-design/ant-design#43267

Verification

  • npm test -- --runInBand — 132 tests and 20 snapshots passed
  • npm run tsc
  • npm run lint — 0 errors (11 existing warnings)
  • Ant Design 6.6.2 integration reproduction: the parent Dropdown closes, the submenu loses its open state, and its popup enters the leave motion

AI assistance disclosure: Codex was used to trace the Ant Design/rc-menu event path, build the regression test, implement the fix, and run verification. The reported behavior and test results were verified locally.

Summary by CodeRabbit

  • Bug 修复

    • 在非内联菜单模式下,当焦点位于菜单容器并按下 Esc 时,现可关闭所有已展开的子菜单。
    • 菜单关闭状态会同步更新,确保展开项被正确清空。
  • 测试

    • 增加了通过键盘 Esc 关闭子菜单的行为验证。
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@nrps9909 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ad9b3cb-6d36-4f5a-8c5c-a1e27c4d66be

📥 Commits

Reviewing files that changed from the base of the PR and between 5e2a3e2 and 3baedee.

📒 Files selected for processing (3)
  • src/Menu.tsx
  • src/hooks/useAccessibility.ts
  • tests/SubMenu.spec.tsx

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

新增无障碍关闭回调。非 inline 模式下,根菜单接收 Escape 时清空所有打开状态并转发键盘事件。新增测试验证子菜单关闭及 onOpenChange([])

Changes

无障碍关闭流程

Layer / File(s) Summary
关闭回调与钩子 wiring
src/Menu.tsx, src/hooks/useAccessibility.ts
Menu 在存在打开菜单项时调用 triggerOpenKeys(EMPTY_LIST, true),并将关闭回调传入 useAccessibility
Escape 关闭处理与测试
src/hooks/useAccessibility.ts, tests/SubMenu.spec.tsx
inline 模式下,菜单容器直接接收 Escape 时关闭菜单、转发原始事件,并通过测试验证所有子菜单关闭及 onOpenChange([])

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 3baed

Pressing Escape on a focused root menu now closes its open popup submenus while preserving existing inline-menu and item-focused behavior. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: zombiej, afc163

Poem

小兔挥爪按下 Escape 键
菜单层层合上不再显
空数组轻轻落入状态中
子菜单跟随根菜单归零
键盘事件继续向前跑

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题“fix: close submenus on root Escape”准确概括了根菜单按下 Escape 时关闭子菜单的主要变更。
Linked Issues check ✅ Passed PR 实现了问题 #43267 的核心要求:当根菜单获得焦点并触发 Escape 时,通过 triggerAccessibilityClose 清空打开状态,从而关闭弹出子菜单。测试覆盖了鼠标打开子菜单后在根菜单触发 Escape 的场景。
Out of Scope Changes check ✅ Passed 变更仅涉及 Menu.tsx、useAccessibility.ts 和对应测试。新增关闭回调、处理根菜单 Escape,以及验证子菜单关闭,均直接服务于问题 #43267。未发现无关代码变更。
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

1 participant