File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
spec/pivotal-ui-react/portals
src/pivotal-ui-react/portals Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -191,4 +191,18 @@ describe('Portals', function() {
191191 expect ( orangeWheatley ) . toContainText ( 'Stop panicking!' ) ;
192192 } ) ;
193193 } ) ;
194+
195+ describe ( 'when the source is rendered significantly after the destination' , ( ) => {
196+ it ( 'renders the source portal into the destination portal' , ( ) => {
197+ ReactDOM . render ( ( < div > < div className = "orange" > < PortalDestination name = "chell" /> </ div > </ div > ) , root ) ;
198+ expect ( '.orange' ) . not . toHaveText ( 'Potato' ) ;
199+ ReactDOM . render ( < div > < div className = "orange" > < PortalDestination name = "chell" /> </ div > < div className = "blue" >
200+ < PortalSource name = "chell" >
201+ < Potato />
202+ </ PortalSource >
203+ </ div > </ div > , root ) ;
204+ expect ( '.blue' ) . not . toHaveText ( 'Potato' ) ;
205+ expect ( '.orange' ) . toHaveText ( 'Potato' ) ;
206+ } ) ;
207+ } ) ;
194208} ) ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export const reset = () => {
2020export class PortalSource extends React . PureComponent {
2121 static propTypes = {
2222 name : PropTypes . string . isRequired
23- }
23+ } ;
2424
2525 constructor ( props , context ) {
2626 super ( props , context ) ;
@@ -29,6 +29,7 @@ export class PortalSource extends React.PureComponent {
2929
3030 componentWillMount ( ) {
3131 emitter . on ( 'destination' , this . setDestination ) ;
32+ this . setDestination ( ) ;
3233 this . componentDidUpdate ( ) ;
3334 }
3435
@@ -49,7 +50,7 @@ export class PortalSource extends React.PureComponent {
4950 const { destination} = this . state ;
5051 const destinationPortal = destinationPortals [ this . props . name ] ;
5152 if ( destination && destination . portal === destinationPortal ) return ;
52- this . setState ( { destination : destinationPortal && { portal : destinationPortal , root : createRoot ( destinationPortal ) } } ) ;
53+ this . setState ( { destination : destinationPortal && { portal : destinationPortal , root : createRoot ( destinationPortal ) } } , this . componentDidUpdate ) ;
5354 }
5455
5556 render ( ) {
You can’t perform that action at this time.
0 commit comments