Skip to content

Commit b8f8d36

Browse files
committed
Add support for React Fragments to CardList and FormLayout (#44)
Fragments are not traversed with `React.children.map()` [1][2] so we are using the `react-keyed-flatten-children` bundle to flatten the children to a one-dimensional array. This is necessary to be able to pass props to children of these layouts. [1] https://reactjs.org/docs/react-api.html#reactchildrenmap [2] reactjs/rfcs#61 (comment)
1 parent 4441aaf commit b8f8d36

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

package-lock.json

Lines changed: 14 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"normalize.css": "^8.0.1",
1616
"prop-types": "^15.7.2",
1717
"react": "^16.13.1",
18-
"react-dom": "^16.13.1"
18+
"react-dom": "^16.13.1",
19+
"react-keyed-flatten-children": "^1.2.0"
1920
},
2021
"devDependencies": {
2122
"@babel/cli": "^7.8.4",

src/lib/components/layout/CardList/CardList.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import flattenChildren from 'react-keyed-flatten-children';
12
import PropTypes from 'prop-types';
23
import React from 'react';
34
import styles from './CardList.scss';
@@ -19,7 +20,7 @@ const CardList = (props) => {
1920
className={styles.root}
2021
{...other}
2122
>
22-
{React.Children.map(children, (child) => {
23+
{flattenChildren(children).map((child) => {
2324
if (!React.isValidElement(child)) {
2425
return null;
2526
}

src/lib/components/layout/FormLayout/FormLayout.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import flattenChildren from 'react-keyed-flatten-children';
12
import PropTypes from 'prop-types';
23
import React from 'react';
34
import styles from './FormLayout.scss';
@@ -66,7 +67,7 @@ const FormLayout = (props) => {
6667
].join(' ')}
6768
style={inlineStyle(customLabelWidth, labelAutoWidthFallback)}
6869
>
69-
{React.Children.map(children, (child) => {
70+
{flattenChildren(children).map((child) => {
7071
if (!React.isValidElement(child)) {
7172
return null;
7273
}

0 commit comments

Comments
 (0)