Skip to content

Commit 71fde7d

Browse files
committed
refactor: use rc-util Portal switchScrollingEffect
1 parent 4973df1 commit 71fde7d

File tree

1 file changed

+3
-43
lines changed

1 file changed

+3
-43
lines changed

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> {
@@ -80,10 +71,12 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
8071
private sentinelEnd: HTMLElement;
8172
private dialogMouseDown: boolean;
8273
private timeoutId: number;
74+
private switchScrollingEffect: () => void;
8375

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

8982
componentDidMount() {
@@ -376,39 +369,6 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
376369
return transitionName;
377370
}
378371

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

0 commit comments

Comments
 (0)