Skip to content

Commit

Permalink
fix: right click popup should be closed on mousedown target element (#…
Browse files Browse the repository at this point in the history
…246)

* fix: right click popup should be closed on mousedown target element

* update contextMenu test

* simulate mousedown event differently so it wont break mobile test

* fix code coverage for contextmenu test
  • Loading branch information
rinick authored May 6, 2021
1 parent 5f4bf49 commit 88f9c68
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ export function generateTrigger(
const root = this.getRootDomNode();
const popupNode = this.getPopupDomNode();
if (
!contains(root, target) &&
// mousedown on the target should also close popup when action is contextMenu.
// https://github.com/ant-design/ant-design/issues/29853
(!contains(root, target) || this.isContextMenuOnly()) &&
!contains(popupNode, target) &&
!this.hasPopupMouseDown
) {
Expand Down Expand Up @@ -702,6 +704,14 @@ export function generateTrigger(
);
}

isContextMenuOnly() {
const { action } = this.props;
return (
action === 'contextMenu' ||
(action.length === 1 && action[0] === 'contextMenu')
);
}

isContextMenuToShow() {
const { action, showAction } = this.props;
return (
Expand Down
10 changes: 10 additions & 0 deletions tests/basic.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ describe('Trigger.Basic', () => {

wrapper.trigger('contextMenu');
expect(wrapper.isHidden()).toBeFalsy();

act(() => {
wrapper
.instance()
.onDocumentClick({ target: wrapper.find('.target').getDOMNode() });
jest.runAllTimers();
wrapper.update();
});

expect(wrapper.isHidden()).toBeTruthy();
});

describe('afterPopupVisibleChange can be triggered', () => {
Expand Down

0 comments on commit 88f9c68

Please sign in to comment.