fix: 修复了嵌套 Dropdown 点击子菜单项时,父级菜单会意外关闭导致点击事件丢失的问题 #3119
+137
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR description
此 PR 修复了嵌套 Dropdown 场景下,点击子菜单项会导致父级 Dropdown 意外关闭的问题。
问题原因: 点击子菜单时, mousedown 事件会冒泡到 window ,触发了父级 Dropdown 绑定在 window 上的 onClickOutside 监听器,导致父级被误判为“外部点击”而关闭。
修复方案: 在 Dropdown 的内容容器(content wrapper)上监听 mousedown 事件,并调用 e.nativeEvent.stopImmediatePropagation() 阻止事件冒泡,从而避免触发父级的关闭逻辑。此修改已通过回归测试,并验证了对多级嵌套场景的有效性。
Fixes #3118
🇨🇳 Chinese