File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 9494 "lodash.tonumber" : " ^4.0.3" ,
9595 "prop-types" : " ^15.5.8" ,
9696 "react-popper" : " ^0.8.3" ,
97- "react-portal" : " ^4.1.2" ,
9897 "react-transition-group" : " ^2.2.1"
9998 },
10099 "peerDependencies" : {
101- "react" : " ^0.14.9 || ^15.3.0 || ^ 16.0.0" ,
102- "react-dom" : " ^0.14.9 || ^15.3.0 || ^ 16.0.0"
100+ "react" : " ^16.0.0" ,
101+ "react-dom" : " ^16.0.0"
103102 },
104103 "devDependencies" : {
105104 "babel-cli" : " ^6.14.0" ,
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import PropTypes from 'prop-types' ;
3- import { Portal } from 'react-portal' ;
43import classNames from 'classnames' ;
4+ import Portal from './Portal' ;
55import Fade from './Fade' ;
66import {
77 getOriginalBodyPadding ,
@@ -191,8 +191,10 @@ class Modal extends React.Component {
191191 }
192192
193193 destroy ( ) {
194- document . body . removeChild ( this . _element ) ;
195- this . _element = null ;
194+ if ( this . _element ) {
195+ document . body . removeChild ( this . _element ) ;
196+ this . _element = null ;
197+ }
196198
197199 const modalOpenClassName = mapToCssModules ( 'modal-open' , this . props . cssModule ) ;
198200 // Use regex to prevent matching `modal-open` as part of a different class, e.g. `my-modal-opened`
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import ReactDOM from 'react-dom' ;
3+ import PropTypes from 'prop-types' ;
4+ import { canUseDOM } from './utils' ;
5+
6+ const propTypes = {
7+ children : PropTypes . node . isRequired ,
8+ node : PropTypes . any
9+ } ;
10+
11+ class Portal extends React . Component {
12+ componentWillUnmount ( ) {
13+ if ( this . defaultNode ) {
14+ document . body . removeChild ( this . defaultNode ) ;
15+ }
16+ this . defaultNode = null ;
17+ }
18+
19+ render ( ) {
20+ if ( ! canUseDOM ) {
21+ return null ;
22+ }
23+
24+ if ( ! this . props . node && ! this . defaultNode ) {
25+ this . defaultNode = document . createElement ( 'div' ) ;
26+ document . body . appendChild ( this . defaultNode ) ;
27+ }
28+
29+ return ReactDOM . createPortal (
30+ this . props . children ,
31+ this . props . node || this . defaultNode
32+ ) ;
33+ }
34+ }
35+
36+ Portal . propTypes = propTypes ;
37+
38+ export default Portal ;
Original file line number Diff line number Diff line change @@ -199,3 +199,9 @@ export const PopperPlacements = [
199199 'left' ,
200200 'left-start' ,
201201] ;
202+
203+ export const canUseDOM = ! ! (
204+ typeof window !== 'undefined' &&
205+ window . document &&
206+ window . document . createElement
207+ ) ;
Original file line number Diff line number Diff line change @@ -6659,12 +6659,6 @@ react-popper@^0.8.3:
66596659 popper.js "^1.12.9"
66606660 prop-types "^15.6.0"
66616661
6662- react-portal@^4.1.2 :
6663- version "4.1.2"
6664- resolved "https://registry.yarnpkg.com/react-portal/-/react-portal-4.1.2.tgz#7f28f3c8c2ed5c541907c0ed0f24e8996acf627f"
6665- dependencies :
6666- prop-types "^15.5.8"
6667-
66686662react-prism@^4.3.2 :
66696663 version "4.3.2"
66706664 resolved "https://registry.yarnpkg.com/react-prism/-/react-prism-4.3.2.tgz#5c07609539b3ba6f45eb33e7d6a3588df3270c21"
You can’t perform that action at this time.
0 commit comments