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; diff --git a/packages/material-ui/src/GridListTile/GridListTile.test.js b/packages/material-ui/src/GridListTile/GridListTile.test.js index 46f57ef212dabf..9a742051b30723 100644 --- a/packages/material-ui/src/GridListTile/GridListTile.test.js +++ b/packages/material-ui/src/GridListTile/GridListTile.test.js @@ -76,6 +76,7 @@ describe('', () => { classes={{ imgFullWidth: 'imgFullWidth foo', imgFullHeight: 'imgFullHeight' }} > test + {null} , ); instance = wrapper.instance();