@@ -492,6 +492,7 @@ function totalCount() {
492
492
Object . defineProperty ( exports , "__esModule" , {
493
493
value : true
494
494
} ) ;
495
+ exports . canUseDOM = undefined ;
495
496
496
497
var _exenv = __webpack_require__ ( 20 ) ;
497
498
@@ -503,8 +504,9 @@ var EE = _exenv2.default;
503
504
504
505
var SafeHTMLElement = EE . canUseDOM ? window . HTMLElement : { } ;
505
506
507
+ var canUseDOM = exports . canUseDOM = EE . canUseDOM ;
508
+
506
509
exports . default = SafeHTMLElement ;
507
- module . exports = exports [ 'default' ] ;
508
510
509
511
/***/ } ) ,
510
512
/* 10 */
@@ -579,7 +581,8 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
579
581
var portalClassName = exports . portalClassName = 'ReactModalPortal' ;
580
582
var bodyOpenClassName = exports . bodyOpenClassName = 'ReactModal__Body--open' ;
581
583
582
- var renderSubtreeIntoContainer = _reactDom2 . default . unstable_renderSubtreeIntoContainer ;
584
+ var isReact16 = _reactDom2 . default . createPortal !== undefined ;
585
+ var createPortal = isReact16 ? _reactDom2 . default . createPortal : _reactDom2 . default . unstable_renderSubtreeIntoContainer ;
583
586
584
587
function getParentElement ( parentSelector ) {
585
588
return parentSelector ( ) ;
@@ -600,28 +603,36 @@ var Modal = function (_Component) {
600
603
}
601
604
602
605
return _ret = ( _temp = ( _this = _possibleConstructorReturn ( this , ( _ref = Modal . __proto__ || Object . getPrototypeOf ( Modal ) ) . call . apply ( _ref , [ this ] . concat ( args ) ) ) , _this ) , _this . removePortal = function ( ) {
603
- _reactDom2 . default . unmountComponentAtNode ( _this . node ) ;
606
+ ! isReact16 && _reactDom2 . default . unmountComponentAtNode ( _this . node ) ;
604
607
var parent = getParentElement ( _this . props . parentSelector ) ;
605
608
parent . removeChild ( _this . node ) ;
609
+ } , _this . portalRef = function ( ref ) {
610
+ _this . portal = ref ;
606
611
} , _this . renderPortal = function ( props ) {
607
- _this . portal = renderSubtreeIntoContainer ( _this , _react2 . default . createElement ( _ModalPortal2 . default , _extends ( { defaultStyles : Modal . defaultStyles } , props ) ) , _this . node ) ;
612
+ var portal = createPortal ( _this , _react2 . default . createElement ( _ModalPortal2 . default , _extends ( { defaultStyles : Modal . defaultStyles } , props ) ) , _this . node ) ;
613
+ _this . portalRef ( portal ) ;
608
614
} , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
609
615
}
610
616
611
617
_createClass ( Modal , [ {
612
618
key : 'componentDidMount' ,
613
619
value : function componentDidMount ( ) {
614
- this . node = document . createElement ( 'div' ) ;
620
+ if ( ! _safeHTMLElement . canUseDOM ) return ;
621
+
622
+ if ( ! isReact16 ) {
623
+ this . node = document . createElement ( 'div' ) ;
624
+ }
615
625
this . node . className = this . props . portalClassName ;
616
626
617
627
var parent = getParentElement ( this . props . parentSelector ) ;
618
628
parent . appendChild ( this . node ) ;
619
629
620
- this . renderPortal ( this . props ) ;
630
+ ! isReact16 && this . renderPortal ( this . props ) ;
621
631
}
622
632
} , {
623
633
key : 'componentWillReceiveProps' ,
624
634
value : function componentWillReceiveProps ( newProps ) {
635
+ if ( ! _safeHTMLElement . canUseDOM ) return ;
625
636
var isOpen = newProps . isOpen ;
626
637
// Stop unnecessary renders if modal is remaining closed
627
638
@@ -635,19 +646,20 @@ var Modal = function (_Component) {
635
646
newParent . appendChild ( this . node ) ;
636
647
}
637
648
638
- this . renderPortal ( newProps ) ;
649
+ ! isReact16 && this . renderPortal ( newProps ) ;
639
650
}
640
651
} , {
641
652
key : 'componentWillUpdate' ,
642
653
value : function componentWillUpdate ( newProps ) {
654
+ if ( ! _safeHTMLElement . canUseDOM ) return ;
643
655
if ( newProps . portalClassName !== this . props . portalClassName ) {
644
656
this . node . className = newProps . portalClassName ;
645
657
}
646
658
}
647
659
} , {
648
660
key : 'componentWillUnmount' ,
649
661
value : function componentWillUnmount ( ) {
650
- if ( ! this . node || ! this . portal ) return ;
662
+ if ( ! _safeHTMLElement . canUseDOM || ! this . node || ! this . portal ) return ;
651
663
652
664
var state = this . portal . state ;
653
665
var now = Date . now ( ) ;
@@ -666,23 +678,24 @@ var Modal = function (_Component) {
666
678
} , {
667
679
key : 'render' ,
668
680
value : function render ( ) {
669
- return null ;
681
+ if ( ! _safeHTMLElement . canUseDOM || ! isReact16 ) {
682
+ return null ;
683
+ }
684
+
685
+ if ( ! this . node && isReact16 ) {
686
+ this . node = document . createElement ( 'div' ) ;
687
+ }
688
+
689
+ return createPortal ( _react2 . default . createElement ( _ModalPortal2 . default , _extends ( { ref : this . portalRef ,
690
+ defaultStyles : Modal . defaultStyles
691
+ } , this . props ) ) , this . node ) ;
670
692
}
671
693
} ] , [ {
672
694
key : 'setAppElement' ,
673
695
value : function setAppElement ( element ) {
674
696
ariaAppHider . setElement ( element ) ;
675
697
}
676
698
677
- /* eslint-disable no-console */
678
-
679
- } , {
680
- key : 'injectCSS' ,
681
- value : function injectCSS ( ) {
682
- undefined !== "production" && console . warn ( 'React-Modal: injectCSS has been deprecated ' + 'and no longer has any effect. It will be removed in a later version' ) ;
683
- }
684
- /* eslint-enable no-console */
685
-
686
699
/* eslint-disable react/no-unused-prop-types */
687
700
688
701
/* eslint-enable react/no-unused-prop-types */
0 commit comments