diff --git a/package.json b/package.json index 0ca4d0a2..df06df73 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "dependencies": { "@babel/runtime": "^7.10.1", "classnames": "^2.2.6", + "omit.js": "^2.0.2", "rc-util": "^5.6.2" } } diff --git a/src/DrawerChild.tsx b/src/DrawerChild.tsx index 10a5f387..abc4d102 100644 --- a/src/DrawerChild.tsx +++ b/src/DrawerChild.tsx @@ -1,7 +1,8 @@ +import * as React from 'react'; import classnames from 'classnames'; import getScrollBarSize from 'rc-util/lib/getScrollBarSize'; import KeyCode from 'rc-util/lib/KeyCode'; -import * as React from 'react'; +import omit from 'omit.js'; import { IDrawerChildProps } from './IDrawerPropTypes'; @@ -284,9 +285,8 @@ class DrawerChild extends React.Component { }; private toggleScrollingToDrawerAndBody = (right: number) => { - const { getOpenCount, getContainer, showMask, open } = this.props; + const { getContainer, showMask, open } = this.props; const container = getContainer && getContainer(); - const openCount = getOpenCount && getOpenCount(); // 处理 body 滚动 if (container && container.parentNode === document.body && showMask) { const eventArray = ['touchstart']; @@ -300,9 +300,6 @@ class DrawerChild extends React.Component { if (right) { this.addScrollingEffect(right); } - if (openCount === 1) { - document.body.style.overflow = 'hidden'; - } document.body.style.touchAction = 'none'; // 手机禁滚 domArray.forEach((item, i) => { @@ -317,10 +314,6 @@ class DrawerChild extends React.Component { ); }); } else if (this.getCurrentDrawerSome()) { - // 没有弹框的状态下清除 overflow; - if (!openCount) { - document.body.style.overflow = ''; - } document.body.style.touchAction = ''; if (right) { this.remScrollingEffect(right); @@ -524,7 +517,7 @@ class DrawerChild extends React.Component { }); return (
HTMLElement; getOpenCount?: () => number; scrollLocker?: ScrollLocker; + switchScrollingEffect?: () => void; } diff --git a/tests/__snapshots__/drawer.spec.tsx.snap b/tests/__snapshots__/drawer.spec.tsx.snap index 359eadff..69119cf2 100644 --- a/tests/__snapshots__/drawer.spec.tsx.snap +++ b/tests/__snapshots__/drawer.spec.tsx.snap @@ -42,7 +42,7 @@ exports[`Drawer render dom 1`] = `