Skip to content

Commit 5b580a4

Browse files
committed
fix #2
1 parent 25b5cea commit 5b580a4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-drawer-menu",
3-
"version": "0.5.3",
3+
"version": "0.5.4",
44
"description": "drawer menu animation component for react",
55
"keywords": [
66
"react",

src/Drawer.jsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import classnames from 'classnames';
55
import { dataToArray, transitionEnd } from './utils';
66

7+
const windowIsUndefined = typeof window === 'undefined';
78
class Drawer extends React.PureComponent {
89
static propTypes = {
910
wrapperClassName: PropTypes.string,
@@ -79,7 +80,7 @@ class Drawer extends React.PureComponent {
7980
}
8081

8182
getParentAndLevelDom = () => {
82-
if (typeof document === 'undefined') {
83+
if (windowIsUndefined) {
8384
return;
8485
}
8586
const { level, parent } = this.props;
@@ -229,12 +230,14 @@ class Drawer extends React.PureComponent {
229230
}
230231
});
231232
// 处理 body 滚动
232-
if (open) {
233-
document.body.addEventListener('mousewheel', this.removeScroll);
234-
document.body.addEventListener('touchmove', this.removeScroll);
235-
} else {
236-
document.body.removeEventListener('mousewheel', this.removeScroll);
237-
document.body.removeEventListener('touchmove', this.removeScroll);
233+
if (!windowIsUndefined) {
234+
if (open) {
235+
document.body.addEventListener('mousewheel', this.removeScroll);
236+
document.body.addEventListener('touchmove', this.removeScroll);
237+
} else {
238+
document.body.removeEventListener('mousewheel', this.removeScroll);
239+
document.body.removeEventListener('touchmove', this.removeScroll);
240+
}
238241
}
239242
if (onChange && this.isOpenChange) {
240243
onChange(open);
@@ -311,6 +314,9 @@ class Drawer extends React.PureComponent {
311314
}
312315

313316
defaultGetContainer = () => {
317+
if (windowIsUndefined) {
318+
return null;
319+
}
314320
const container = document.createElement('div');
315321
this.parent.appendChild(container);
316322
if (this.props.wrapperClassName) {

0 commit comments

Comments
 (0)