Skip to content

Commit

Permalink
Allow ReactDOM.createPortal to be mocked in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Deverell committed Oct 15, 2018
1 parent 1b561fc commit 9cd0891
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export const portalClassName = "ReactModalPortal";
export const bodyOpenClassName = "ReactModal__Body--open";

const isReact16 = ReactDOM.createPortal !== undefined;
const createPortal = isReact16
? ReactDOM.createPortal
: ReactDOM.unstable_renderSubtreeIntoContainer;

const getCreatePortal = () =>
isReact16
? ReactDOM.createPortal
: ReactDOM.unstable_renderSubtreeIntoContainer;

function getParentElement(parentSelector) {
return parentSelector();
Expand Down Expand Up @@ -180,6 +182,7 @@ class Modal extends Component {
};

renderPortal = props => {
const createPortal = getCreatePortal();
const portal = createPortal(
this,
<ModalPortal defaultStyles={Modal.defaultStyles} {...props} />,
Expand All @@ -197,6 +200,7 @@ class Modal extends Component {
this.node = document.createElement("div");
}

const createPortal = getCreatePortal();
return createPortal(
<ModalPortal
ref={this.portalRef}
Expand Down

0 comments on commit 9cd0891

Please sign in to comment.