Skip to content
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

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) &&
rinick marked this conversation as resolved.
Show resolved Hide resolved
!contains(popupNode, target) &&
!this.hasPopupMouseDown
) {
Expand Down Expand Up @@ -700,6 +702,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
32 changes: 16 additions & 16 deletions tests/basic.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ describe('Trigger.Basic', () => {
);

wrapper.trigger();
expect(
wrapper
.find('Popup')
.find('.x-content')
.text(),
).toBe('tooltip2');
expect(wrapper.find('Popup').find('.x-content').text()).toBe('tooltip2');

wrapper.trigger();
expect(wrapper.isHidden()).toBeTruthy();
Expand All @@ -173,12 +168,7 @@ describe('Trigger.Basic', () => {
);

wrapper.trigger();
expect(
wrapper
.find('Popup')
.find('.x-content')
.text(),
).toBe('tooltip3');
expect(wrapper.find('Popup').find('.x-content').text()).toBe('tooltip3');

wrapper.trigger();
expect(wrapper.isHidden()).toBeTruthy();
Expand Down Expand Up @@ -215,6 +205,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 Expand Up @@ -509,7 +509,7 @@ describe('Trigger.Basic', () => {
});

describe('stretch', () => {
const createTrigger = stretch =>
const createTrigger = (stretch) =>
mount(
<Trigger
action={['click']}
Expand Down Expand Up @@ -542,7 +542,7 @@ describe('Trigger.Basic', () => {
domSpy.mockRestore();
});

['width', 'height', 'minWidth', 'minHeight'].forEach(prop => {
['width', 'height', 'minWidth', 'minHeight'].forEach((prop) => {
it(prop, () => {
const wrapper = createTrigger(prop);

Expand Down Expand Up @@ -643,7 +643,7 @@ describe('Trigger.Basic', () => {
<div>
<button
type="button"
onMouseDown={e => {
onMouseDown={(e) => {
e.preventDefault();
e.stopPropagation();
}}
Expand Down Expand Up @@ -687,7 +687,7 @@ describe('Trigger.Basic', () => {

describe('getContainer', () => {
it('not trigger when dom not ready', () => {
const getPopupContainer = jest.fn(node => node.parentElement);
const getPopupContainer = jest.fn((node) => node.parentElement);

function Demo() {
return (
Expand Down