11import React from 'react' ;
22import CustomPropTypes from './utils/CustomPropTypes' ;
33import domUtils from './utils/domUtils' ;
4+ import deprecationWarning from './utils/deprecationWarning' ;
45
5- export default {
6+ export const OverlayMixin = {
67 propTypes : {
8+
79 container : CustomPropTypes . mountable
810 } ,
911
10- componentWillUnmount ( ) {
11- this . _unrenderOverlay ( ) ;
12- if ( this . _overlayTarget ) {
13- this . getContainerDOMNode ( )
14- . removeChild ( this . _overlayTarget ) ;
15- this . _overlayTarget = null ;
16- }
12+
13+ componentDidMount ( ) {
14+ this . _renderOverlay ( ) ;
1715 } ,
1816
1917 componentDidUpdate ( ) {
2018 this . _renderOverlay ( ) ;
2119 } ,
2220
23- componentDidMount ( ) {
24- this . _renderOverlay ( ) ;
21+ componentWillUnmount ( ) {
22+ this . _unrenderOverlay ( ) ;
23+ this . _mountOverlayTarget ( ) ;
2524 } ,
2625
2726 _mountOverlayTarget ( ) {
28- this . _overlayTarget = document . createElement ( 'div' ) ;
29- this . getContainerDOMNode ( )
30- . appendChild ( this . _overlayTarget ) ;
27+ if ( ! this . _overlayTarget ) {
28+ this . _overlayTarget = document . createElement ( 'div' ) ;
29+ this . getContainerDOMNode ( )
30+ . appendChild ( this . _overlayTarget ) ;
31+ }
32+ } ,
33+
34+ _unmountOverlayTarget ( ) {
35+ if ( this . _overlayTarget ) {
36+ this . getContainerDOMNode ( )
37+ . removeChild ( this . _overlayTarget ) ;
38+ this . _overlayTarget = null ;
39+ }
3140 } ,
3241
3342 _renderOverlay ( ) {
@@ -39,10 +48,12 @@ export default {
3948
4049 // Save reference to help testing
4150 if ( overlay !== null ) {
51+ this . _mountOverlayTarget ( ) ;
4252 this . _overlayInstance = React . render ( overlay , this . _overlayTarget ) ;
4353 } else {
4454 // Unrender if the component is null for transitions to null
4555 this . _unrenderOverlay ( ) ;
56+ this . _unmountOverlayTarget ( ) ;
4657 }
4758 } ,
4859
@@ -67,3 +78,14 @@ export default {
6778 return React . findDOMNode ( this . props . container ) || domUtils . ownerDocument ( this ) . body ;
6879 }
6980} ;
81+
82+ export default {
83+
84+ ...OverlayMixin ,
85+
86+ componentWillMount ( ) {
87+ deprecationWarning (
88+ 'Overlay mixin' , 'the `<Portal/>` Component'
89+ , 'http://react-bootstrap.github.io/components.html#modals-custom' ) ;
90+ }
91+ } ;
0 commit comments