Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix https://github.com/ant-design/ant-design/issues/24821 #115

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/PortalWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class PortalWrapper extends React.Component {
constructor(props) {
super(props);
const { visible } = props;
openCount = visible ? openCount + 1 : openCount;
if (!windowIsUndefined && this.getParent() === document.body) {
openCount = visible ? openCount + 1 : openCount;
}
this.state = {
_self: this,
};
Expand All @@ -35,8 +37,10 @@ class PortalWrapper extends React.Component {

componentWillUnmount() {
const { visible } = this.props;
// 离开时不会 render, 导到离开时数值不变,改用 func 。。
openCount = visible && openCount ? openCount - 1 : openCount;
if (!windowIsUndefined && this.getParent() === document.body) {
// 离开时不会 render, 导到离开时数值不变,改用 func 。。
openCount = visible && openCount ? openCount - 1 : openCount;
}
this.removeCurrentContainer(visible);
}

Expand All @@ -47,7 +51,7 @@ class PortalWrapper extends React.Component {
visible: prevVisible,
getContainer: prevGetContainer,
} = prevProps;
if (visible !== prevVisible) {
if (visible !== prevVisible && !windowIsUndefined && this.getParent() === document.body) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDerivedStateFromProps 里面不能用 this。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复制粘贴习惯了。。

openCount = visible && !prevVisible ? openCount + 1 : openCount - 1;
}
const getContainerIsFunc =
Expand All @@ -67,6 +71,9 @@ class PortalWrapper extends React.Component {
}

getParent = () => {
if (windowIsUndefined) {
return null;
}
const { getContainer } = this.props;
if (getContainer) {
if (typeof getContainer === 'string') {
Expand Down