-
-
Notifications
You must be signed in to change notification settings - Fork 50k
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
feat: ⌨️ Popconfirm can be closed by pressing ESC #24420
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add tests to make sure this change works as expected?
components/popconfirm/index.tsx
Outdated
const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => { | ||
if (e.key === 'Escape' && e.target === innerContentRef.current) { | ||
settingVisible(false, e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还要判断一下 e.target === innerContentRef.current
,学习了 😂
components/popconfirm/index.tsx
Outdated
React.useEffect(() => { | ||
const timeout = setTimeout(() => { | ||
if (visible) { | ||
innerContentRef.current?.focus(); | ||
} | ||
}); | ||
return () => { | ||
clearTimeout(timeout); | ||
}; | ||
}, [visible]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果在 Popconfirm 受控的情况下,切换了 focus 就不能按 Esc 退出了吧?
找了下默认是怎么做到在外部点击关闭弹窗的,应该是这里 。那么即使在受控的情况下,也不用自己监听外部点击事件了,配置 onVisibleChange
就行了啊。之前还琢磨怎么自己监听实现呢 _(:3J∠)_
Codecov Report
@@ Coverage Diff @@
## feature #24420 +/- ##
========================================
Coverage 98.95% 98.95%
========================================
Files 364 364
Lines 7391 7398 +7
Branches 2000 2054 +54
========================================
+ Hits 7314 7321 +7
Misses 77 77
Continue to review full report at Codecov.
|
components/popconfirm/index.tsx
Outdated
React.useEffect(() => { | ||
const timeout = setTimeout(() => { | ||
if (visible) { | ||
innerContentRef.current?.focus(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样键盘交互焦点就丢了,是不是可以考虑全局监听一下。打开的时候 ESC 关闭?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接绑定在 trigger 上好了,全局监听就复杂了。
components/popconfirm/index.tsx
Outdated
@@ -72,6 +78,12 @@ const Popconfirm = React.forwardRef<unknown, PopconfirmProps>((props, ref) => { | |||
} | |||
}; | |||
|
|||
const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => { | |||
if (e.key === 'Escape' && visible) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeyCode.ESC
/rebase |
27e4935
to
1413693
Compare
超了 0.1 kB.. |
Need to approve |
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
💡 Background and solution
close #15203
📝 Changelog
ESC
now.ESC
关闭。☑️ Self Check before Merge