|
1 | 1 | import React from 'react';
|
2 |
| -import ReactDOM from 'react-dom'; |
| 2 | +import { createPortal } from 'react-dom'; |
3 | 3 | import PropTypes from 'prop-types';
|
4 | 4 | import classnames from 'classnames';
|
5 | 5 | import { dataToArray, transitionEnd } from './utils';
|
@@ -53,9 +53,10 @@ class Drawer extends React.PureComponent {
|
53 | 53 | };
|
54 | 54 | }
|
55 | 55 | componentDidMount() {
|
56 |
| - this.dom = ReactDOM.findDOMNode(this); |
| 56 | + if (this.props.parent) { |
| 57 | + this.container = this.defaultGetContainer(); |
| 58 | + } |
57 | 59 | this.getParentAndLevelDom();
|
58 |
| - this.container = this.props.parent ? this.defaultGetContainer() : this.dom; |
59 | 60 | this.forceUpdate();
|
60 | 61 | }
|
61 | 62 |
|
@@ -85,7 +86,7 @@ class Drawer extends React.PureComponent {
|
85 | 86 | }
|
86 | 87 | const { level, parent } = this.props;
|
87 | 88 | this.levelDom = [];
|
88 |
| - this.parent = parent && document.querySelectorAll(parent)[0] || this.dom.parentNode; |
| 89 | + this.parent = parent && document.querySelectorAll(parent)[0] || this.container.parentNode; |
89 | 90 | if (level === 'all') {
|
90 | 91 | const children = Array.prototype.slice.call(this.parent.children);
|
91 | 92 | children.forEach(child => {
|
@@ -331,14 +332,14 @@ class Drawer extends React.PureComponent {
|
331 | 332 | render() {
|
332 | 333 | const children = this.getChildToRender();
|
333 | 334 | if (!this.props.parent) {
|
334 |
| - return (<div className={this.props.wrapperClassName}> |
| 335 | + return (<div className={this.props.wrapperClassName} ref={(c) => { this.container = c; }}> |
335 | 336 | {children}
|
336 | 337 | </div>);
|
337 | 338 | }
|
338 | 339 | if (!this.container) {
|
339 | 340 | return null;
|
340 | 341 | }
|
341 |
| - return ReactDOM.createPortal(children, this.container); |
| 342 | + return createPortal(children, this.container); |
342 | 343 | }
|
343 | 344 | }
|
344 | 345 |
|
|
0 commit comments