Skip to content

Commit

Permalink
Remove cWRP usage in ModalPortal
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypnosphi authored and diasbruno committed Apr 13, 2018
1 parent e91d59a commit f748406
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,43 +69,42 @@ export default class ModalPortal extends Component {
}

componentDidMount() {
// Focus needs to be set when mounting and already open
if (this.props.isOpen) {
this.setFocusAfterRender(true);
this.open();
}
}

componentWillReceiveProps(newProps) {
componentDidUpdate(prevProps, prevState) {
if (process.env.NODE_ENV !== "production") {
if (newProps.bodyOpenClassName !== this.props.bodyOpenClassName) {
if (prevProps.bodyOpenClassName !== this.props.bodyOpenClassName) {
// eslint-disable-next-line no-console
console.warn(
'React-Modal: "bodyOpenClassName" prop has been modified. ' +
"This may cause unexpected behavior when multiple modals are open."
);
}
if (newProps.htmlOpenClassName !== this.props.htmlOpenClassName) {
if (prevProps.htmlOpenClassName !== this.props.htmlOpenClassName) {
// eslint-disable-next-line no-console
console.warn(
'React-Modal: "htmlOpenClassName" prop has been modified. ' +
"This may cause unexpected behavior when multiple modals are open."
);
}
}
// Focus only needs to be set once when the modal is being opened
if (!this.props.isOpen && newProps.isOpen) {
this.setFocusAfterRender(true);

if (this.props.isOpen && !prevProps.isOpen) {
this.open();
} else if (this.props.isOpen && !newProps.isOpen) {
} else if (!this.props.isOpen && prevProps.isOpen) {
this.close();
}
}

componentDidUpdate() {
if (this.focusAfterRender) {
// Focus only needs to be set once when the modal is being opened
if (
this.props.shouldFocusAfterRender &&
this.state.isOpen &&
!prevState.isOpen
) {
this.focusContent();
this.setFocusAfterRender(false);
}
}

Expand All @@ -114,10 +113,6 @@ export default class ModalPortal extends Component {
clearTimeout(this.closeTimer);
}

setFocusAfterRender = focus => {
this.focusAfterRender = this.props.shouldFocusAfterRender && focus;
};

setOverlayRef = overlay => {
this.overlay = overlay;
this.props.overlayRef && this.props.overlayRef(overlay);
Expand Down

0 comments on commit f748406

Please sign in to comment.