Skip to content

Commit b4c5e33

Browse files
authored
Fix popupStyle zIndex missing (#172)
* 🐛 Fix popupStyle zIndex not working close ant-design/ant-design#21770 * fix unused state
1 parent 5601e49 commit b4c5e33

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

src/Popup.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class Popup extends Component<PopupProps, PopupState> {
9494
targetHeight: undefined,
9595

9696
status: null,
97-
prevVisible: null,
9897
alignClassName: null,
9998
};
10099

@@ -120,7 +119,8 @@ class Popup extends Component<PopupProps, PopupState> {
120119
} else if (visible !== prevVisible) {
121120
if (
122121
visible ||
123-
(supportMotion(mergedMotion) && ['motion', 'AfterMotion', 'stable'].includes(status))
122+
(supportMotion(mergedMotion) &&
123+
['motion', 'AfterMotion', 'stable'].includes(status))
124124
) {
125125
newState.status = null;
126126
} else {
@@ -169,7 +169,13 @@ class Popup extends Component<PopupProps, PopupState> {
169169

170170
default: {
171171
// Go to next status
172-
const queue: PopupStatus[] = ['measure', 'align', null, 'beforeMotion', 'motion'];
172+
const queue: PopupStatus[] = [
173+
'measure',
174+
'align',
175+
null,
176+
'beforeMotion',
177+
'motion',
178+
];
173179
const index = queue.indexOf(status);
174180
const nextStatus = queue[index + 1];
175181
if (index !== -1 && nextStatus) {
@@ -291,16 +297,21 @@ class Popup extends Component<PopupProps, PopupState> {
291297

292298
const mergedStyle: React.CSSProperties = {
293299
...sizeStyle,
294-
...style,
295300
...this.getZIndexStyle(),
301+
...style,
296302
opacity: status === 'stable' || !visible ? undefined : 0,
297303
};
298304

299305
// ================= Motions =================
300306
const mergedMotion = this.getMotion();
301307
let mergedMotionVisible = visible;
302308

303-
if (visible && status !== 'beforeMotion' && status !== 'motion' && status !== 'stable') {
309+
if (
310+
visible &&
311+
status !== 'beforeMotion' &&
312+
status !== 'motion' &&
313+
status !== 'stable'
314+
) {
304315
mergedMotion.motionAppear = false;
305316
mergedMotion.motionEnter = false;
306317
mergedMotion.motionLeave = false;
@@ -312,7 +323,8 @@ class Popup extends Component<PopupProps, PopupState> {
312323

313324
// ================== Align ==================
314325
const mergedAlignDisabled =
315-
!visible || (status !== 'align' && status !== 'aligned' && status !== 'stable');
326+
!visible ||
327+
(status !== 'align' && status !== 'aligned' && status !== 'stable');
316328

317329
// ================== Popup ==================
318330
let mergedPopupVisible = true;
@@ -367,7 +379,14 @@ class Popup extends Component<PopupProps, PopupState> {
367379
};
368380

369381
renderMaskElement = () => {
370-
const { mask, maskMotion, maskTransitionName, maskAnimation, prefixCls, visible } = this.props;
382+
const {
383+
mask,
384+
maskMotion,
385+
maskTransitionName,
386+
maskAnimation,
387+
prefixCls,
388+
visible,
389+
} = this.props;
371390

372391
if (!mask) {
373392
return null;

tests/basic.test.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,23 @@ describe('Trigger.Basic', () => {
595595
.onDocumentClick({ target: wrapper.find('button').instance() });
596596
expect(wrapper.isHidden()).toBeFalsy();
597597
});
598+
599+
// https://github.com/ant-design/ant-design/issues/21770
600+
it('support popupStyle, such as zIndex', () => {
601+
const style = { color: 'red', zIndex: 9999, top: 100 };
602+
const wrapper = mount(
603+
<Trigger
604+
popupVisible
605+
popupStyle={style}
606+
popup={<strong className="x-content">tooltip2</strong>}
607+
>
608+
<div className="target">click</div>
609+
</Trigger>,
610+
);
611+
612+
const popupDomNode = wrapper.instance().getPopupDomNode();
613+
expect(popupDomNode.style.zIndex).toBe(style.zIndex.toString());
614+
expect(popupDomNode.style.color).toBe(style.color);
615+
expect(popupDomNode.style.top).toBe(`${style.top}px`);
616+
});
598617
});

0 commit comments

Comments
 (0)