Skip to content

Commit 4819bde

Browse files
committed
fix: Only remove placement class when showing
1 parent 548d7e8 commit 4819bde

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

src/Popup.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ class Popup extends Component<PopupProps, PopupState> {
104104

105105
private nextFrameId: number = null;
106106

107-
static getDerivedStateFromProps({ visible, ...props }: PopupProps, { prevVisible }: PopupState) {
108-
const newState: Partial<PopupState> = { prevVisible: visible };
107+
static getDerivedStateFromProps(
108+
{ visible, ...props }: PopupProps,
109+
{ prevVisible, status }: PopupState,
110+
) {
111+
const newState: Partial<PopupState> = { prevVisible: visible, status };
109112

110113
const mergedMotion = getMotion(props);
111114

@@ -115,7 +118,7 @@ class Popup extends Component<PopupProps, PopupState> {
115118
} else if (visible !== prevVisible) {
116119
newState.status = visible || supportMotion(mergedMotion) ? null : 'stable';
117120

118-
if (!visible) {
121+
if (visible) {
119122
newState.alignClassName = null;
120123
}
121124
}

tests/point.test.jsx

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,46 @@ describe('Trigger.Point', () => {
8787
});
8888
});
8989

90-
it('placement', () => {
91-
const builtinPlacements = {
90+
describe('placement', () => {
91+
function testPlacement(name, builtinPlacements, afterAll) {
92+
it(name, () => {
93+
const wrapper = mount(
94+
<Demo action={['click']} builtinPlacements={builtinPlacements} popupPlacement="right" />,
95+
);
96+
wrapper.trigger('click', { pageX: 10, pageY: 20 });
97+
98+
const popup = wrapper
99+
.find('.rc-trigger-popup')
100+
.first()
101+
.getDOMNode();
102+
103+
expect(popup.style).toEqual(expect.objectContaining({ left: '-989px', top: '-979px' }));
104+
105+
if (afterAll) {
106+
afterAll(wrapper);
107+
}
108+
});
109+
}
110+
111+
testPlacement('not hit', {
92112
right: {
93113
// This should not hit
94114
points: ['cl'],
95115
},
96-
};
116+
});
97117

98-
const wrapper = mount(
99-
<Demo action={['click']} builtinPlacements={builtinPlacements} popupPlacement="right" />,
118+
testPlacement(
119+
'hit',
120+
{
121+
left: {
122+
points: ['tl'],
123+
},
124+
},
125+
wrapper => {
126+
expect(
127+
wrapper.find('div.rc-trigger-popup').hasClass('rc-trigger-popup-placement-left'),
128+
).toBeTruthy();
129+
},
100130
);
101-
wrapper.trigger('click', { pageX: 10, pageY: 20 });
102-
103-
const popup = wrapper
104-
.find('.rc-trigger-popup')
105-
.first()
106-
.getDOMNode();
107-
108-
expect(popup.style).toEqual(expect.objectContaining({ left: '-989px', top: '-979px' }));
109131
});
110132
});

0 commit comments

Comments
 (0)