Skip to content

fix: the repeated calling of multi-level Trigger triggerOpen method #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

QdabuliuQ
Copy link

@QdabuliuQ QdabuliuQ commented Aug 8, 2025

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

fix ant-design/ant-design#54496

💡 Background and Solution

Quickly moving the mouse in and out of menu items triggers the bug
When the mouse leaves the submenu, it triggers onPopupMouseLeave of the previous parent menu, causing the previous parent menu to close unexpectedly

📝 Change Log

Language Changelog
🇺🇸 English Fix dropdown menu display issues caused by rapid mouse movement between menu items
🇨🇳 Chinese 修复鼠标快速移动进出 dropdown menu 导致 menu 显示异常

Summary by CodeRabbit

  • Bug 修复
    • 优化了鼠标移入/移出弹窗的展示与关闭逻辑:进入触发区域或弹窗时会取消待执行的关闭,避免快速移入移出导致意外关闭,重入/重开行为更顺滑、响应更准确。
    • 无对外接口或声明的变更。

Copy link

coderabbitai bot commented Aug 8, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

修改了 src/index.tsx 中与弹出层鼠标交互相关的逻辑:在触发区和弹出层的鼠标进入处理里添加了对延迟关闭的取消(clearDelay()),并调整/保留了基于打开状态与移动状态的重开判断与注释,未更改导出声明。

Changes

Cohort / File(s) Change Summary
Popup 鼠标事件处理调整
src/index.tsx
在 hover 显示路径的 onMouseEnterCallback 中调用 clearDelay() 以取消待关闭延迟;在 onPopupMouseEnter 中无条件调用 clearDelay() 并保留基于 `(mergedOpen

Sequence Diagram(s)

sequenceDiagram
    participant User as 用户
    participant Trigger as 触发组件
    participant Popup as 弹出层

    User->>Trigger: 鼠标进入触发区
    Trigger->>Popup:(若为 hover)调用 onMouseEnterCallback -> clearDelay() -> 保持/打开 popup

    User->>Popup: 鼠标进入 popup (onPopupMouseEnter)
    Popup->>Popup: clearDelay()
    alt (mergedOpen || inMotion) && 事件目标在 popup 内
        Popup->>Popup: 保持或重开 popup
    end

    User->>Popup: 鼠标离开 popup (onPopupMouseLeave)
    Popup->>Popup: 根据包含判断触发延迟关闭或保持
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
修复 Dropdown 多级菜单快速移出移入子级菜单时父级菜单会关闭的问题(#54496)

Assessment against linked issues: Out-of-scope changes

(无发现超出关联 issue 目标的代码更改)

Possibly related PRs

Suggested reviewers

  • zombieJ
  • MadCcc

Poem

兔儿轻跳过鼠标边,
取消延迟不让门悬,
父子菜单同步眠与醒,
快速来去心不烦,
🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6f0f2b9 and d3468e3.

📒 Files selected for processing (1)
  • src/index.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/index.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/index.tsx (2)

571-572: 类型更改方向正确,但建议补齐 Pointer 对称性

将 onPopupMouseLeave 的类型从 VoidFunction 调整为 React.MouseEventHandler 是合理的,能直接拿到事件对象进行判断。为保证与已绑定的 onPointerEnter 对称,建议在 Popup 上同时绑定 onPointerLeave(可直接复用同一处理函数),以覆盖仅触发 Pointer 事件的设备场景。


598-607: onMouseEnter 条件可简化:contains(event.target) 在此处恒为真

在容器自身的 onMouseEnter 上,event.target 必然是该容器内部节点,因此 popupEle.contains(event.target) 恒为 true,判断多余。可简化以减少误导和冗余逻辑:

-      onPopupMouseEnter = (event) => {
-        // Only trigger re-open when popup is visible or in motion
-        // and ensure the mouse is entering the popup area
-        if (
-          (mergedOpen || inMotion) &&
-          popupEle?.contains(event.target as HTMLElement)
-        ) {
-          triggerOpen(true, mouseEnterDelay);
-        }
-      };
+      onPopupMouseEnter = (event) => {
+        // 仅在可见或过渡中才重开,避免 forceRender 等场景误触
+        if (mergedOpen || inMotion) {
+          triggerOpen(true, mouseEnterDelay);
+        }
+      };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 867a20c and 5884b91.

📒 Files selected for processing (1)
  • src/index.tsx (3 hunks)

Copy link

codecov bot commented Aug 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.75%. Comparing base (867a20c) to head (5884b91).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #564   +/-   ##
=======================================
  Coverage   97.75%   97.75%           
=======================================
  Files          12       12           
  Lines         801      802    +1     
  Branches      235      244    +9     
=======================================
+ Hits          783      784    +1     
  Misses         18       18           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@afc163 afc163 requested review from zombieJ and Copilot August 9, 2025 14:18
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in dropdown menu behavior where rapid mouse movement between menu items caused unexpected menu closures. The issue occurred when leaving a submenu would incorrectly trigger the parent menu's onPopupMouseLeave event, causing the parent menu to close unexpectedly.

  • Modified onPopupMouseLeave to accept a mouse event parameter and validate the event target
  • Added a condition to only trigger menu closure when the mouse actually leaves the popup element
  • Updated function signature to properly handle React mouse events

@QdabuliuQ QdabuliuQ changed the title Fixed onPopupMouseLeave triggering error fix: the repeated calling of multi-level Trigger triggerOpen method Aug 14, 2025
@@ -576,6 +576,8 @@ export function generateTrigger(

if (hoverToShow) {
const onMouseEnterCallback = (event: React.MouseEvent) => {
// Clear any delayed close operations
clearDelay();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearDelay 是对自身的触发进行清理,这个在鼠标事件 trigger open 的时候已经调用了,并不会影响多层的逻辑。应该是通过 parentContext 来告知 parent 需要复活才对。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

官网Dropdown组件 多级菜单 示例鼠标快速移出移入子级菜单,子级菜单不会关闭,父级菜单会关闭
3 participants