-
-
Notifications
You must be signed in to change notification settings - Fork 237
feat: support close popups by escape key #594
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
Changes from 5 commits
e32a0d8
4591871
26500eb
58270c9
36dcac9
84659ec
38363a6
3d870c9
76db217
c3c97d7
8bbd563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ import useAlign from './hooks/useAlign'; | |
| import useDelay from './hooks/useDelay'; | ||
| import useWatch from './hooks/useWatch'; | ||
| import useWinClick from './hooks/useWinClick'; | ||
| import type { PortalProps } from '@rc-component/portal'; | ||
|
|
||
| import type { | ||
| ActionType, | ||
| AlignType, | ||
|
|
@@ -51,6 +53,7 @@ export interface TriggerRef { | |
| // New version will not wrap popup with `rc-trigger-popup-content` when multiple children | ||
|
|
||
| export interface TriggerProps { | ||
| onKeyDown?: (event: KeyboardEvent) => void; | ||
aojunhao123 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| children: | ||
| | React.ReactElement<any> | ||
| | ((info: { open: boolean }) => React.ReactElement<any>); | ||
|
|
@@ -146,6 +149,7 @@ export function generateTrigger( | |
| const { | ||
| prefixCls = 'rc-trigger-popup', | ||
| children, | ||
| onKeyDown, | ||
|
|
||
| // Action | ||
| action = 'hover', | ||
|
|
@@ -419,6 +423,13 @@ export function generateTrigger( | |
| }, delay); | ||
| }; | ||
|
|
||
| const onEsc: PortalProps['onEsc'] = ({ top, event }) => { | ||
| if (top) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 还需要判断一下是否是 click 触发的,如果是 hover 触发的 esc 关闭是不合理的
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里我理解是不对的,Esc应该始终能够触发Tooltip关闭。这也是无障碍规范里提到过的,然后就是我观察了其它主流的a11y友好的组件库中,Tooltip的行为也都是支持hover后Esc关闭的 |
||
| triggerOpen(false); | ||
| } | ||
| onKeyDown?.(event); | ||
| }; | ||
|
|
||
| // ========================== Motion ============================ | ||
| const [inMotion, setInMotion] = React.useState(false); | ||
|
|
||
|
|
@@ -830,6 +841,7 @@ export function generateTrigger( | |
| forceRender={forceRender} | ||
| autoDestroy={mergedAutoDestroy} | ||
| getPopupContainer={getPopupContainer} | ||
| onEsc={onEsc} | ||
| // Arrow | ||
| align={alignInfo} | ||
| arrow={innerArrow} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.