Skip to content

Commit a295827

Browse files
committed
fix parent
1 parent b5026b1 commit a295827

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

examples/assets/index.less

+8
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@
3030
left: 0;
3131
transform: translateX(0px);
3232
}
33+
}
34+
35+
.parent-demo {
36+
position: relative;
37+
overflow: hidden;
38+
.drawer {
39+
position: absolute;
40+
}
3341
}

examples/parent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const MenuItemGroup = Menu.ItemGroup;
1616
// 父级的 transform 距阵必须为 none; 否则将影响 fixed;
1717

1818
ReactDom.render((
19-
<div >
19+
<div className="parent-demo">
2020
<Drawer parent={null} width="240px">
2121
<Menu
2222
style={{ width: 240 }}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-drawer-menu",
3-
"version": "0.5.5",
3+
"version": "0.5.6",
44
"description": "drawer menu animation component for react",
55
"keywords": [
66
"react",

src/Drawer.jsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
2+
import { createPortal } from 'react-dom';
33
import PropTypes from 'prop-types';
44
import classnames from 'classnames';
55
import { dataToArray, transitionEnd } from './utils';
@@ -53,9 +53,10 @@ class Drawer extends React.PureComponent {
5353
};
5454
}
5555
componentDidMount() {
56-
this.dom = ReactDOM.findDOMNode(this);
56+
if (this.props.parent) {
57+
this.container = this.defaultGetContainer();
58+
}
5759
this.getParentAndLevelDom();
58-
this.container = this.props.parent ? this.defaultGetContainer() : this.dom;
5960
this.forceUpdate();
6061
}
6162

@@ -85,7 +86,7 @@ class Drawer extends React.PureComponent {
8586
}
8687
const { level, parent } = this.props;
8788
this.levelDom = [];
88-
this.parent = parent && document.querySelectorAll(parent)[0] || this.dom.parentNode;
89+
this.parent = parent && document.querySelectorAll(parent)[0] || this.container.parentNode;
8990
if (level === 'all') {
9091
const children = Array.prototype.slice.call(this.parent.children);
9192
children.forEach(child => {
@@ -331,14 +332,14 @@ class Drawer extends React.PureComponent {
331332
render() {
332333
const children = this.getChildToRender();
333334
if (!this.props.parent) {
334-
return (<div className={this.props.wrapperClassName}>
335+
return (<div className={this.props.wrapperClassName} ref={(c) => { this.container = c; }}>
335336
{children}
336337
</div>);
337338
}
338339
if (!this.container) {
339340
return null;
340341
}
341-
return ReactDOM.createPortal(children, this.container);
342+
return createPortal(children, this.container);
342343
}
343344
}
344345

0 commit comments

Comments
 (0)