Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(Modal): handle init modal in SSR (#1495)
* fix(Modal): handle init modal in SSR

* fix(Modal): move init to did mount of component and rewrite test cases

* fix(Modal): handle tigger to re-render in case `isOpen` is true on init
  • Loading branch information
lh0x00 authored and TheSharpieOne committed May 21, 2019
1 parent 51608ef commit c844ab1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 49 deletions.
11 changes: 5 additions & 6 deletions src/Modal.js
Expand Up @@ -100,15 +100,16 @@ class Modal extends React.Component {
this.manageFocusAfterClose = this.manageFocusAfterClose.bind(this);

this.state = {
isOpen: props.isOpen,
isOpen: false,
};
}

if (props.isOpen) {
componentDidMount() {
if (this.props.isOpen) {
this.init();
this.setState({ isOpen: true })
}
}

componentDidMount() {
if (this.props.onEnter) {
this.props.onEnter();
}
Expand Down Expand Up @@ -341,7 +342,6 @@ class Modal extends React.Component {
} = this.props;

if (!!this._element && (this.state.isOpen || !unmountOnClose)) {

const isModalHidden = !!this._element && !this.state.isOpen && !unmountOnClose;
this._element.style.display = isModalHidden ? 'none' : 'block';

Expand Down Expand Up @@ -415,7 +415,6 @@ class Modal extends React.Component {
</Portal>
);
}

return null;
}
}
Expand Down

0 comments on commit c844ab1

Please sign in to comment.