fix: 修复 Dropdown 嵌套使用 absolute 时子级菜单项点击无法触发 onClick 的问题 - #2217
Merged
Merged
Conversation
问题原因:a512cfe7 将 Dropdown 的 document 事件从 mousedown 改为 click, 导致嵌套 absolute 的子 Dropdown 菜单项的 React 合成 onClick 无法触发。 修复方案:将事件改回 mousedown,并在 clickAway 中增加对 trigger button 区域的 判断,避免 mousedown 与 click 的竞态问题(受控模式下点击 placeholder 无法关闭)。 Regression: since 2.0.29 (#2187)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
问题描述
Dropdown 嵌套使用
absolute属性时(内层 Dropdown 的列表 portal 到指定容器),点击子级菜单项无法触发onClick回调,弹出层直接消失。原因分析
#2187(a512cfe) 将 Dropdown 的toggleDocumentEvent从mousedown改为click,导致:click事件的 capture 阶段 clickAway 先于 React 合成事件处理onClick无法正常触发修复方案
toggleDocumentEvent的事件改回mousedownclickAway中增加对 trigger button 区域的判断:如果 mousedown 发生在 Dropdown 自身的 button 元素内,跳过 clickAway,由handleFocus(click 事件)处理 toggle这样既修复了嵌套 absolute Dropdown 的问题,又不会回退 #2187 解决的两个问题:
Regression
Since 2.0.29 (#2187)
关联
修复 #2187 引入的副作用