Skip to content

Commit cab5f00

Browse files
committed
fix getContainer no body, overflow: hidden does not delete
1 parent 256f6dd commit cab5f00

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/DrawerChild.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,18 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
9898
} catch (err) {}
9999
this.passive = passiveSupported ? { passive: false } : false;
100100
}
101-
const { open } = this.props;
101+
const { open, getContainer } = this.props;
102+
const container = getContainer && getContainer();
102103
this.drawerId = `drawer_id_${Number(
103104
(Date.now() + Math.random())
104105
.toString()
105106
.replace('.', Math.round(Math.random() * 9).toString()),
106107
).toString(16)}`;
107108
this.getLevelDom(this.props);
108109
if (open) {
109-
currentDrawer[this.drawerId] = open;
110+
if (container && container.parentNode === document.body) {
111+
currentDrawer[this.drawerId] = open;
112+
}
110113
// 默认打开状态时推出 level;
111114
this.openLevelTransition();
112115
this.forceUpdate(() => {
@@ -116,12 +119,15 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
116119
}
117120

118121
public componentDidUpdate(prevProps: IDrawerChildProps) {
119-
const { open } = this.props;
122+
const { open, getContainer } = this.props;
123+
const container = getContainer && getContainer();
120124
if (open !== prevProps.open) {
121125
if (open) {
122126
this.domFocus();
123127
}
124-
currentDrawer[this.drawerId] = !!open;
128+
if (container && container.parentNode === document.body) {
129+
currentDrawer[this.drawerId] = !!open;
130+
}
125131
this.openLevelTransition();
126132
}
127133
}
@@ -238,7 +244,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
238244
) => {
239245
const { placement, levelMove, duration, ease, showMask } = this.props;
240246
// router 切换时可能会导至页面失去滚动条,所以需要时时获取。
241-
this.levelDom.forEach((dom) => {
247+
this.levelDom.forEach(dom => {
242248
dom.style.transition = `transform ${duration} ${ease}`;
243249
addEventListener(dom, transitionEnd, this.transitionEnd);
244250
let levelValue = open ? value : 0;
@@ -285,6 +291,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
285291
const { getOpenCount, getContainer, showMask, open } = this.props;
286292
const container = getContainer && getContainer();
287293
const openCount = getOpenCount && getOpenCount();
294+
console.log(openCount);
288295
// 处理 body 滚动
289296
if (container && container.parentNode === document.body && showMask) {
290297
const eventArray = ['touchstart'];
@@ -436,7 +443,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
436443
};
437444

438445
private getCurrentDrawerSome = () =>
439-
!Object.keys(currentDrawer).some((key) => currentDrawer[key]);
446+
!Object.keys(currentDrawer).some(key => currentDrawer[key]);
440447

441448
private getLevelDom = ({ level, getContainer }: IDrawerChildProps) => {
442449
if (windowIsUndefined) {
@@ -460,8 +467,8 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
460467
}
461468
});
462469
} else if (level) {
463-
dataToArray(level).forEach((key) => {
464-
document.querySelectorAll(key).forEach((item) => {
470+
dataToArray(level).forEach(key => {
471+
document.querySelectorAll(key).forEach(item => {
465472
this.levelDom.push(item);
466473
});
467474
});
@@ -556,7 +563,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
556563
className={`${prefixCls}-mask`}
557564
onClick={maskClosable ? onClose : undefined}
558565
style={maskStyle}
559-
ref={(c) => {
566+
ref={c => {
560567
this.maskDom = c as HTMLElement;
561568
}}
562569
/>
@@ -569,13 +576,13 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
569576
width: isNumeric(width) ? `${width}px` : width,
570577
height: isNumeric(height) ? `${height}px` : height,
571578
}}
572-
ref={(c) => {
579+
ref={c => {
573580
this.contentWrapper = c as HTMLElement;
574581
}}
575582
>
576583
<div
577584
className={`${prefixCls}-content`}
578-
ref={(c) => {
585+
ref={c => {
579586
this.contentDom = c as HTMLElement;
580587
}}
581588
onTouchStart={

0 commit comments

Comments
 (0)