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() {
191
191
expect ( orangeWheatley ) . toContainText ( 'Stop panicking!' ) ;
192
192
} ) ;
193
193
} ) ;
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
+ } ) ;
194
208
} ) ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export const reset = () => {
20
20
export class PortalSource extends React . PureComponent {
21
21
static propTypes = {
22
22
name : PropTypes . string . isRequired
23
- }
23
+ } ;
24
24
25
25
constructor ( props , context ) {
26
26
super ( props , context ) ;
@@ -29,6 +29,7 @@ export class PortalSource extends React.PureComponent {
29
29
30
30
componentWillMount ( ) {
31
31
emitter . on ( 'destination' , this . setDestination ) ;
32
+ this . setDestination ( ) ;
32
33
this . componentDidUpdate ( ) ;
33
34
}
34
35
@@ -49,7 +50,7 @@ export class PortalSource extends React.PureComponent {
49
50
const { destination} = this . state ;
50
51
const destinationPortal = destinationPortals [ this . props . name ] ;
51
52
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 ) ;
53
54
}
54
55
55
56
render ( ) {
You can’t perform that action at this time.
0 commit comments