diff --git a/src/index.tsx b/src/index.tsx index d221707e..e7ca681d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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 ) { @@ -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 ( diff --git a/tests/basic.test.jsx b/tests/basic.test.jsx index c01ab7bf..b7f42da2 100644 --- a/tests/basic.test.jsx +++ b/tests/basic.test.jsx @@ -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', () => {