Skip to content

Commit

Permalink
[GridList] Clean the rendering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jun 28, 2018
1 parent 05b59db commit 5c9ba30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions packages/material-ui/src/GridList/GridList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
});
})}
Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/GridListTile/GridListTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ class GridListTile extends React.Component {
<EventListener target="window" onResize={this.handleResize} />
<div className={classes.tile}>
{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;
Expand Down

0 comments on commit 5c9ba30

Please sign in to comment.