Skip to content

Commit d78bded

Browse files
committed
fix(utils): Fix autogenerated grid coords
Fixes react-grid-layout#368, broken by eac7e08
1 parent ff75de7 commit d78bded

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/utils.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,12 @@ export function synchronizeLayoutWithChildren(initialLayout: Layout, children: R
359359
initialLayout = initialLayout || [];
360360

361361
// Generate one layout item per child.
362-
let layout: Layout = React.Children.map(children, (child: React.Element<any>) => {
362+
let layout: Layout = [];
363+
React.Children.forEach(children, (child: React.Element<any>, i: number) => {
363364
// Don't overwrite if it already exists.
364365
const exists = getLayoutItem(initialLayout, child.key || "1" /* FIXME satisfies Flow */);
365366
if (exists) {
366-
return cloneLayoutItem(exists);
367+
layout[i] = cloneLayoutItem(exists);
367368
} else {
368369
if (process.env.NODE_ENV !== 'production' && child.props._grid) {
369370
console.warn('`_grid` properties on children have been deprecated as of React 15.2. ' + // eslint-disable-line
@@ -377,10 +378,11 @@ export function synchronizeLayoutWithChildren(initialLayout: Layout, children: R
377378
validateLayout([g], 'ReactGridLayout.children');
378379
}
379380

380-
return cloneLayoutItem({...g, i: child.key});
381+
layout[i] = cloneLayoutItem({...g, i: child.key});
382+
} else {
383+
// Nothing provided: ensure this is added to the bottom
384+
layout[i] = cloneLayoutItem({w: 1, h: 1, x: 0, y: bottom(layout), i: child.key || "1"});
381385
}
382-
// Nothing provided: ensure this is added to the bottom
383-
return cloneLayoutItem({w: 1, h: 1, x: 0, y: bottom(layout), i: child.key || "1"});
384386
}
385387
});
386388

0 commit comments

Comments
 (0)