@@ -37,16 +37,19 @@ class TetherContent extends React.Component {// eslint-disable-line react/prefer
3737
3838 static defaultProps = defaultProps ;
3939
40+ constructor ( props ) {
41+ super ( props ) ;
42+
43+ this . element = document . createElement ( 'div' ) ;
44+ }
45+
4046 componentDidMount = ( ) => {
4147 this . handleProps ( ) ;
4248 }
4349
4450 componentDidUpdate = ( prevProps ) => {
4551 if ( this . props . isOpen !== prevProps . isOpen ) {
4652 this . handleProps ( ) ;
47- } else if ( this . element ) {
48- // rerender
49- this . renderIntoSubtree ( ) ;
5053 }
5154 }
5255
@@ -92,10 +95,8 @@ class TetherContent extends React.Component {// eslint-disable-line react/prefer
9295 hide = ( ) => {
9396 document . removeEventListener ( 'click' , this . handleDocumentClick , true ) ;
9497
95- if ( this . element ) {
98+ if ( this . element . parentElement === document . body ) {
9699 document . body . removeChild ( this . element ) ;
97- ReactDOM . unmountComponentAtNode ( this . element ) ;
98- this . element = null ;
99100 }
100101
101102 if ( this . tether ) {
@@ -110,10 +111,8 @@ class TetherContent extends React.Component {// eslint-disable-line react/prefer
110111 show = ( ) => {
111112 document . addEventListener ( 'click' , this . handleDocumentClick , true ) ;
112113
113- this . element = document . createElement ( 'div' ) ;
114114 this . element . className = this . props . className ;
115115 document . body . appendChild ( this . element ) ;
116- this . renderIntoSubtree ( ) ;
117116 this . tether = new Tether ( this . getTetherConfig ( ) ) ;
118117 if ( this . props . tetherRef ) {
119118 this . props . tetherRef ( this . tether ) ;
@@ -129,14 +128,6 @@ class TetherContent extends React.Component {// eslint-disable-line react/prefer
129128 return this . props . toggle ( ) ;
130129 }
131130
132- renderIntoSubtree = ( ) => {
133- ReactDOM . unstable_renderSubtreeIntoContainer (
134- this ,
135- this . renderChildren ( ) ,
136- this . element
137- ) ;
138- }
139-
140131 renderChildren = ( ) => {
141132 const { children, style } = this . props ;
142133 return React . cloneElement (
@@ -146,8 +137,13 @@ class TetherContent extends React.Component {// eslint-disable-line react/prefer
146137 }
147138
148139 render ( ) {
149- return (
150- null
140+ if ( ! this . props . isOpen ) {
141+ return null ;
142+ }
143+
144+ return ReactDOM . createPortal (
145+ this . renderChildren ( ) ,
146+ this . element
151147 ) ;
152148 }
153149}
0 commit comments