From 5c9ba3008dd2c040139aaaa9de301f618c8fb4a4 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Thu, 28 Jun 2018 09:18:02 +0200 Subject: [PATCH] [GridList] Clean the rendering logic --- packages/material-ui/src/GridList/GridList.js | 12 ++++++------ .../material-ui/src/GridListTile/GridListTile.js | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/material-ui/src/GridList/GridList.js b/packages/material-ui/src/GridList/GridList.js index 1076da6df65b1a..e0da6259482442 100644 --- a/packages/material-ui/src/GridList/GridList.js +++ b/packages/material-ui/src/GridList/GridList.js @@ -33,21 +33,21 @@ function GridList(props) { style={{ margin: -spacing / 2, ...style }} {...other} > - {React.Children.map(children, currentChild => { - if (!React.isValidElement(currentChild)) { + {React.Children.map(children, child => { + if (!React.isValidElement(child)) { return null; } - const childCols = currentChild.props.cols || 1; - const childRows = currentChild.props.rows || 1; + const childCols = child.props.cols || 1; + const childRows = child.props.rows || 1; - return React.cloneElement(currentChild, { + return React.cloneElement(child, { style: Object.assign( { width: `${(100 / cols) * childCols}%`, height: cellHeight === 'auto' ? 'auto' : cellHeight * childRows + spacing, padding: spacing / 2, }, - currentChild.props.style, + child.props.style, ), }); })} diff --git a/packages/material-ui/src/GridListTile/GridListTile.js b/packages/material-ui/src/GridListTile/GridListTile.js index 16b988e30b660d..b6f8f22a30110f 100644 --- a/packages/material-ui/src/GridListTile/GridListTile.js +++ b/packages/material-ui/src/GridListTile/GridListTile.js @@ -90,7 +90,11 @@ class GridListTile extends React.Component {
{React.Children.map(children, child => { - if (child && child.type === 'img') { + if (!React.isValidElement(child)) { + return null; + } + + if (child.type === 'img') { return React.cloneElement(child, { ref: node => { this.imgElement = node;