@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
4
4
import classnames from 'classnames' ;
5
5
import { dataToArray , transitionEnd } from './utils' ;
6
6
7
+ const windowIsUndefined = typeof window === 'undefined' ;
7
8
class Drawer extends React . PureComponent {
8
9
static propTypes = {
9
10
wrapperClassName : PropTypes . string ,
@@ -79,7 +80,7 @@ class Drawer extends React.PureComponent {
79
80
}
80
81
81
82
getParentAndLevelDom = ( ) => {
82
- if ( typeof document === 'undefined' ) {
83
+ if ( windowIsUndefined ) {
83
84
return ;
84
85
}
85
86
const { level, parent } = this . props ;
@@ -229,12 +230,14 @@ class Drawer extends React.PureComponent {
229
230
}
230
231
} ) ;
231
232
// 处理 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
+ }
238
241
}
239
242
if ( onChange && this . isOpenChange ) {
240
243
onChange ( open ) ;
@@ -311,6 +314,9 @@ class Drawer extends React.PureComponent {
311
314
}
312
315
313
316
defaultGetContainer = ( ) => {
317
+ if ( windowIsUndefined ) {
318
+ return null ;
319
+ }
314
320
const container = document . createElement ( 'div' ) ;
315
321
this . parent . appendChild ( container ) ;
316
322
if ( this . props . wrapperClassName ) {
0 commit comments