Skip to content

Commit 073e976

Browse files
authored
Merge pull request react-grid-layout#766 from brian-eightsolutions/fix-for-no-compaction
Fix for bugs when no compaction is on.
2 parents e4c5f09 + e768e47 commit 073e976

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/utils.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function childrenEqual(a: ReactChildren, b: ReactChildren): boolean {
122122
* Given two layoutitems, check if they collide.
123123
*/
124124
export function collides(l1: LayoutItem, l2: LayoutItem): boolean {
125-
if (l1 === l2) return false; // same element
125+
if (l1.i === l2.i) return false; // same element
126126
if (l1.x + l1.w <= l2.x) return false; // l1 is left of l2
127127
if (l1.x >= l2.x + l2.w) return false; // l1 is right of l2
128128
if (l1.y + l1.h <= l2.y) return false; // l1 is above l2
@@ -185,7 +185,11 @@ function resolveCompactionCollision(
185185
) {
186186
const sizeProp = heightWidth[axis];
187187
item[axis] += 1;
188-
const itemIndex = layout.indexOf(item);
188+
const itemIndex = layout
189+
.map(layoutItem => {
190+
return layoutItem.i;
191+
})
192+
.indexOf(item.i);
189193

190194
// Go through each item we collide with.
191195
for (let i = itemIndex + 1; i < layout.length; i++) {
@@ -441,7 +445,8 @@ export function moveElementAwayFromCollision(
441445
cols: number
442446
): Layout {
443447
const compactH = compactType === "horizontal";
444-
const compactV = compactType === "vertical";
448+
// Compact vertically if not set to horizontal
449+
const compactV = compactType !== "horizontal";
445450
const preventCollision = false; // we're already colliding
446451

447452
// If there is enough space above the collision to put this element, move it there.

0 commit comments

Comments
 (0)