Skip to content

Commit 88f9c68

Browse files
authored
fix: right click popup should be closed on mousedown target element (#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
1 parent 5f4bf49 commit 88f9c68

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ export function generateTrigger(
405405
const root = this.getRootDomNode();
406406
const popupNode = this.getPopupDomNode();
407407
if (
408-
!contains(root, target) &&
408+
// mousedown on the target should also close popup when action is contextMenu.
409+
// https://github.com/ant-design/ant-design/issues/29853
410+
(!contains(root, target) || this.isContextMenuOnly()) &&
409411
!contains(popupNode, target) &&
410412
!this.hasPopupMouseDown
411413
) {
@@ -702,6 +704,14 @@ export function generateTrigger(
702704
);
703705
}
704706

707+
isContextMenuOnly() {
708+
const { action } = this.props;
709+
return (
710+
action === 'contextMenu' ||
711+
(action.length === 1 && action[0] === 'contextMenu')
712+
);
713+
}
714+
705715
isContextMenuToShow() {
706716
const { action, showAction } = this.props;
707717
return (

tests/basic.test.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ describe('Trigger.Basic', () => {
151151

152152
wrapper.trigger('contextMenu');
153153
expect(wrapper.isHidden()).toBeFalsy();
154+
155+
act(() => {
156+
wrapper
157+
.instance()
158+
.onDocumentClick({ target: wrapper.find('.target').getDOMNode() });
159+
jest.runAllTimers();
160+
wrapper.update();
161+
});
162+
163+
expect(wrapper.isHidden()).toBeTruthy();
154164
});
155165

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

0 commit comments

Comments
 (0)