Skip to content
Open
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
36 changes: 17 additions & 19 deletions components/utilities/dialog/portal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Portal extends Component {
this.portalNode = null;
this.state = {
isOpen: false,
portalContainer: null,
};
}

Expand Down Expand Up @@ -68,12 +69,19 @@ class Portal extends Component {
this.portalNodeInstance = this.props.onMount
? this.props.onMount(undefined, { portal: this.portalNode })
: this.portalNode;

if (!this.props.portalMount) {
this.updatePortal();
this.setState({ portalContainer: this.portalNode });
}
}
}

unmountPortal() {
if (this.portalNode) {
ReactDOM.unmountComponentAtNode(this.portalNode);
if (this.portalMount) {
ReactDOM.unmountComponentAtNode(this.portalNode);
}
this.portalNode.parentNode.removeChild(this.portalNode);
}
this.portalNode = null;
Expand Down Expand Up @@ -119,28 +127,18 @@ class Portal extends Component {
this.updatePortal(); // update after subtree renders
},
});
} else {
// actual render
ReactDOM.unstable_renderSubtreeIntoContainer(
this,
this.getChildren(),
this.portalNode,
() => {
this.updatePortal(); // update after subtree renders

if (this.state.isOpen === false) {
if (this.props.onOpen) {
this.props.onOpen(undefined, { portal: this.getChildren() });
}
this.setState({ isOpen: true });
}
}
);
} else if (this.state.isOpen === false) {
if (this.props.onOpen) {
this.props.onOpen(undefined, { portal: this.getChildren() });
}
this.setState({ isOpen: true });
}
}

render() {
return null;
return !this.props.portalMount && this.state.portalContainer
? ReactDOM.createPortal(this.props.children, this.state.portalContainer)
: null;
}
}

Expand Down