File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,9 @@ var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
25
25
var REACT_ELEMENT_TYPE =
26
26
( typeof Symbol === 'function' && Symbol . for && Symbol . for ( 'react.element' ) ) ||
27
27
0xeac7 ;
28
-
28
+ const REACT_PORTAL_TYPE =
29
+ ( typeof Symbol === 'function' && Symbol . for && Symbol . for ( 'react.portal' ) ) ||
30
+ 0xeaca ;
29
31
var SEPARATOR = '.' ;
30
32
var SUBSEPARATOR = ':' ;
31
33
@@ -125,7 +127,8 @@ function traverseAllChildrenImpl(
125
127
type === 'number' ||
126
128
// The following is inlined from ReactElement. This means we can optimize
127
129
// some checks. React Fiber also inlines this logic for similar purposes.
128
- ( type === 'object' && children . $$typeof === REACT_ELEMENT_TYPE )
130
+ ( type === 'object' && children . $$typeof === REACT_ELEMENT_TYPE ) ||
131
+ ( type === 'object' && children . $$typeof === REACT_PORTAL_TYPE )
129
132
) {
130
133
callback (
131
134
traverseContext ,
Original file line number Diff line number Diff line change @@ -48,6 +48,31 @@ describe('ReactChildren', () => {
48
48
expect ( mappedChildren [ 0 ] ) . toEqual ( < span key = ".$simple" /> ) ;
49
49
} ) ;
50
50
51
+ it ( 'should support Portal components' , ( ) => {
52
+ const context = { } ;
53
+ const callback = jasmine . createSpy ( ) . and . callFake ( function ( kid , index ) {
54
+ expect ( this ) . toBe ( context ) ;
55
+ return kid ;
56
+ } ) ;
57
+ const ReactDOM = require ( 'react-dom' ) ;
58
+ const portalContainer = document . createElement ( 'div' ) ;
59
+
60
+ const simpleChild = < span key = "simple" /> ;
61
+ const portal = ReactDOM . createPortal ( simpleChild , portalContainer ) ;
62
+ const instance = < div > { portal } </ div > ;
63
+
64
+ React . Children . forEach ( instance . props . children , callback , context ) ;
65
+ expect ( callback ) . toHaveBeenCalledWith ( portal , 0 ) ;
66
+ callback . calls . reset ( ) ;
67
+ const mappedChildren = React . Children . map (
68
+ instance . props . children ,
69
+ callback ,
70
+ context ,
71
+ ) ;
72
+ expect ( callback ) . toHaveBeenCalledWith ( portal , 0 ) ;
73
+ expect ( mappedChildren [ 0 ] ) . toEqual ( portal ) ;
74
+ } ) ;
75
+
51
76
it ( 'should treat single arrayless child as being in array' , ( ) => {
52
77
var context = { } ;
53
78
var callback = jasmine . createSpy ( ) . and . callFake ( function ( kid , index ) {
You can’t perform that action at this time.
0 commit comments