File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 2
2
type ReactNode ,
3
3
Children ,
4
4
cloneElement ,
5
+ Fragment ,
5
6
isValidElement ,
6
7
JSXElementConstructor ,
7
8
} from 'react'
@@ -86,7 +87,19 @@ export function extendChildren(
86
87
props : ( childProps : Record < string , unknown > ) => Record < string , unknown > ,
87
88
displayName ?: string ,
88
89
) : ReactNode {
89
- return Children . map ( children , ( child ) => {
90
+ let childrenToIterateOver = children
91
+ if ( Children . count ( children ) === 0 ) {
92
+ return children
93
+ }
94
+ if (
95
+ Children . count ( children ) === 1 &&
96
+ isValidElement ( children ) &&
97
+ children . type === Fragment
98
+ ) {
99
+ childrenToIterateOver = children . props . children as ReactNode
100
+ }
101
+
102
+ return Children . map ( childrenToIterateOver , ( child ) => {
90
103
if ( ! isValidElement ( child ) ) {
91
104
return child
92
105
}
You can’t perform that action at this time.
0 commit comments