Skip to content

Commit e57f149

Browse files
authored
fix: Hide popup no need re-align (#203)
1 parent b8b8cb2 commit e57f149

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ export function generateTrigger(
583583
* @param popupVisible Show or not the popup element
584584
* @param event SyntheticEvent, used for `pointAlign`
585585
*/
586-
setPopupVisible(popupVisible, event?) {
586+
setPopupVisible(popupVisible: boolean, event?: { pageX: number, pageY: number }) {
587587
const { alignPoint } = this.props;
588588
const { popupVisible: prevPopupVisible } = this.state;
589589

@@ -597,7 +597,7 @@ export function generateTrigger(
597597
}
598598

599599
// Always record the point position since mouseEnterDelay will delay the show
600-
if (alignPoint && event) {
600+
if (alignPoint && event && popupVisible) {
601601
this.setPoint(event);
602602
}
603603
}

tests/point.test.jsx

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ describe('Trigger.Point', () => {
1616
});
1717

1818
class Demo extends React.Component {
19-
popup = <div className="point-popup">POPUP</div>;
19+
popup = (<div className="point-popup">POPUP</div>);
2020

2121
render() {
2222
return (
23-
<Trigger popup={this.popup} popupAlign={{ points: ['tl'] }} alignPoint {...this.props}>
23+
<Trigger
24+
popup={this.popup}
25+
popupAlign={{ points: ['tl'] }}
26+
alignPoint
27+
{...this.props}
28+
>
2429
<div className="point-region" />
2530
</Trigger>
2631
);
@@ -36,7 +41,9 @@ describe('Trigger.Point', () => {
3641
.first()
3742
.getDOMNode();
3843

39-
expect(popup.style).toEqual(expect.objectContaining({ left: '-989px', top: '-979px' }));
44+
expect(popup.style).toEqual(
45+
expect.objectContaining({ left: '-989px', top: '-979px' }),
46+
);
4047
});
4148

4249
it('hover', () => {
@@ -48,33 +55,59 @@ describe('Trigger.Point', () => {
4855
.first()
4956
.getDOMNode();
5057

51-
expect(popup.style).toEqual(expect.objectContaining({ left: '-989px', top: '-979px' }));
58+
expect(popup.style).toEqual(
59+
expect.objectContaining({ left: '-989px', top: '-979px' }),
60+
);
5261
});
5362

5463
describe('contextMenu', () => {
5564
it('basic', () => {
56-
const wrapper = mount(<Demo action={['contextMenu']} />);
65+
const wrapper = mount(
66+
<Demo action={['contextMenu']} hideAction={['click']} />,
67+
);
5768
wrapper.trigger('contextMenu', { pageX: 10, pageY: 20 });
5869

5970
const popup = wrapper
6071
.find('.rc-trigger-popup')
6172
.first()
6273
.getDOMNode();
6374

64-
expect(popup.style).toEqual(expect.objectContaining({ left: '-989px', top: '-979px' }));
75+
expect(popup.style).toEqual(
76+
expect.objectContaining({ left: '-989px', top: '-979px' }),
77+
);
78+
79+
// Not trigger point update when close
80+
const clickEvent = {};
81+
const pagePropDefine = {
82+
get: () => {
83+
throw new Error('should not read when close');
84+
},
85+
};
86+
Object.defineProperties(clickEvent, {
87+
pageX: pagePropDefine,
88+
pageY: pagePropDefine,
89+
});
90+
wrapper
91+
.find('Trigger')
92+
.instance()
93+
.onClick(clickEvent);
6594
});
6695

6796
// https://github.com/ant-design/ant-design/issues/17043
6897
it('not prevent default', done => {
69-
const wrapper = mount(<Demo showAction={['contextMenu']} hideAction={['click']} />);
98+
const wrapper = mount(
99+
<Demo showAction={['contextMenu']} hideAction={['click']} />,
100+
);
70101
wrapper.trigger('contextMenu', { pageX: 10, pageY: 20 });
71102

72103
const popup = wrapper
73104
.find('.rc-trigger-popup')
74105
.first()
75106
.getDOMNode();
76107

77-
expect(popup.style).toEqual(expect.objectContaining({ left: '-989px', top: '-979px' }));
108+
expect(popup.style).toEqual(
109+
expect.objectContaining({ left: '-989px', top: '-979px' }),
110+
);
78111

79112
// Click to close
80113
wrapper.trigger('click', {
@@ -91,7 +124,11 @@ describe('Trigger.Point', () => {
91124
function testPlacement(name, builtinPlacements, afterAll) {
92125
it(name, () => {
93126
const wrapper = mount(
94-
<Demo action={['click']} builtinPlacements={builtinPlacements} popupPlacement="right" />,
127+
<Demo
128+
action={['click']}
129+
builtinPlacements={builtinPlacements}
130+
popupPlacement="right"
131+
/>,
95132
);
96133
wrapper.trigger('click', { pageX: 10, pageY: 20 });
97134

@@ -100,7 +137,9 @@ describe('Trigger.Point', () => {
100137
.first()
101138
.getDOMNode();
102139

103-
expect(popup.style).toEqual(expect.objectContaining({ left: '-989px', top: '-979px' }));
140+
expect(popup.style).toEqual(
141+
expect.objectContaining({ left: '-989px', top: '-979px' }),
142+
);
104143

105144
if (afterAll) {
106145
afterAll(wrapper);
@@ -124,7 +163,9 @@ describe('Trigger.Point', () => {
124163
},
125164
wrapper => {
126165
expect(
127-
wrapper.find('div.rc-trigger-popup').hasClass('rc-trigger-popup-placement-left'),
166+
wrapper
167+
.find('div.rc-trigger-popup')
168+
.hasClass('rc-trigger-popup-placement-left'),
128169
).toBeTruthy();
129170
},
130171
);

0 commit comments

Comments
 (0)