Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 243
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e32a0d8459187126500eb58270c936dcac984659ec38363a63d870c976db217c3c97d78bbd563File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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, | ||
| @@ -347,6 +349,7 @@ export function generateTrigger( | ||
| getPopupContainer, | ||
| getPopupClassNameFromAlign, | ||
| id, | ||
| onEsc, | ||
| })); | ||
| // Handle controlled state changes for UniqueProvider | ||
| @@ -419,6 +422,12 @@ export function generateTrigger( | ||
| }, delay); | ||
| }; | ||
| function onEsc({ top }: Parameters<PortalProps['onEsc']>[0]) { | ||
aojunhao123 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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 关闭是不合理的 ContributorAuthor 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); | ||
| } | ||
| } | ||
| // ========================== Motion ============================ | ||
| const [inMotion, setInMotion] = React.useState(false); | ||
| @@ -830,6 +839,7 @@ export function generateTrigger( | ||
| forceRender={forceRender} | ||
| autoDestroy={mergedAutoDestroy} | ||
| getPopupContainer={getPopupContainer} | ||
| onEsc={onEsc} | ||
| // Arrow | ||
| align={alignInfo} | ||
| arrow={innerArrow} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -374,4 +374,19 @@ describe('Trigger.Unique', () => { | ||
| // Verify onAlign was called due to target change | ||
| expect(mockOnAlign).toHaveBeenCalled(); | ||
| }); | ||
| it('esc should close unique popup', async () => { | ||
| const { container,baseElement } = render( | ||
| <UniqueProvider> | ||
| <Trigger action={['click']} popup={<div>Popup</div>} unique> | ||
| <div className="target" /> | ||
| </Trigger> | ||
| </UniqueProvider>, | ||
| ); | ||
| fireEvent.click(container.querySelector('.target')); | ||
| expect(baseElement.querySelector('.rc-trigger-popup-hidden')).toBeFalsy(); | ||
| fireEvent.keyDown(window, { key: 'Escape' }); | ||
| expect(baseElement.querySelector('.rc-trigger-popup-hidden')).toBeTruthy(); | ||
| }); | ||
aojunhao123 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.