Skip to content

Commit caa81a6

Browse files
authored
Merge pull request #166 from react-component/refactor-switch-scrolling-effect
refactor: use rc-util Portal switchScrollingEffect
2 parents 6be8113 + 8bdd422 commit caa81a6

File tree

3 files changed

+36
-44
lines changed

3 files changed

+36
-44
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@
8181
"dependencies": {
8282
"babel-runtime": "6.x",
8383
"rc-animate": "2.x",
84-
"rc-util": "^4.8.1"
84+
"rc-util": "^4.16.1"
8585
}
8686
}

src/Dialog.tsx

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
33
import KeyCode from 'rc-util/lib/KeyCode';
44
import contains from 'rc-util/lib/Dom/contains';
5-
import switchScrollingEffect from 'rc-util/lib/switchScrollingEffect';
65
import Animate from 'rc-animate';
76
import LazyRenderBox from './LazyRenderBox';
87
import IDialogPropTypes from './IDialogPropTypes';
@@ -45,17 +44,9 @@ function offset(el: any) {
4544
return pos;
4645
}
4746

48-
// https://github.com/ant-design/ant-design/issues/19340
49-
// https://github.com/ant-design/ant-design/issues/19332
50-
interface ICacheOverflow {
51-
overflowX?: string;
52-
overflowY?: string;
53-
overflow?: string;
54-
}
55-
let cacheOverflow: ICacheOverflow = {};
56-
5747
export interface IDialogChildProps extends IDialogPropTypes {
5848
getOpenCount: () => number;
49+
switchScrollingEffect?: () => void;
5950
}
6051

6152
export default class Dialog extends React.Component<IDialogChildProps, any> {
@@ -81,10 +72,12 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
8172
private sentinelEnd: HTMLElement;
8273
private dialogMouseDown: boolean;
8374
private timeoutId: number;
75+
private switchScrollingEffect: () => void;
8476

8577
constructor(props: IDialogChildProps) {
8678
super(props);
8779
this.titleId = `rcDialogTitle${uuid++}`;
80+
this.switchScrollingEffect = props.switchScrollingEffect || (() => {});
8881
}
8982

9083
componentDidMount() {
@@ -377,39 +370,6 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
377370
return transitionName;
378371
}
379372

380-
switchScrollingEffect = () => {
381-
const { getOpenCount } = this.props;
382-
const openCount = getOpenCount();
383-
384-
if (openCount === 1) {
385-
if (cacheOverflow.hasOwnProperty('overflowX')) {
386-
return;
387-
}
388-
cacheOverflow = {
389-
overflowX: document.body.style.overflowX,
390-
overflowY: document.body.style.overflowY,
391-
overflow: document.body.style.overflow,
392-
} as ICacheOverflow;
393-
switchScrollingEffect();
394-
// Must be set after switchScrollingEffect
395-
document.body.style.overflow = 'hidden';
396-
} else if (!openCount) {
397-
// IE browser doesn't merge overflow style, need to set it separately
398-
// https://github.com/ant-design/ant-design/issues/19393
399-
if (cacheOverflow.overflow !== undefined) {
400-
document.body.style.overflow = cacheOverflow.overflow;
401-
}
402-
if (cacheOverflow.overflowX !== undefined) {
403-
document.body.style.overflowX = cacheOverflow.overflowX;
404-
}
405-
if (cacheOverflow.overflowY !== undefined) {
406-
document.body.style.overflowY = cacheOverflow.overflowY;
407-
}
408-
cacheOverflow = {};
409-
switchScrollingEffect(true);
410-
}
411-
}
412-
413373
close = (e: any) => {
414374
const { onClose } = this.props;
415375
if (onClose) {

tests/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,36 @@ describe('dialog', () => {
400400
})
401401
expect(document.body.style.overflow).to.be('scroll');
402402
})
403+
404+
it('afterClose', (done) => {
405+
const dialog = ReactDOM.render((
406+
<DialogWrap
407+
afterClose={done}
408+
>
409+
<div>afterClose</div>
410+
</DialogWrap>
411+
),container);
412+
dialog.setState({
413+
visible: true,
414+
});
415+
dialog.setState({
416+
visible: false,
417+
});
418+
});
419+
420+
it('zIndex', () => {
421+
const dialog = ReactDOM.render((
422+
<DialogWrap
423+
zIndex={1000}
424+
>
425+
<div>afterClose</div>
426+
</DialogWrap>
427+
),container);
428+
dialog.setState({
429+
visible: true,
430+
});
431+
432+
expect($('.rc-dialog-wrap').css("zIndex")).to.be('1000');
433+
434+
});
403435
});

0 commit comments

Comments
 (0)