Skip to content

Commit e80fd59

Browse files
authored
Merge pull request #3464 from adumesny/master
taller widget can drop into shorter sub-grid
2 parents ea35082 + 9813983 commit e80fd59

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎doc/CHANGES.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Change log
154154
* feat: [#3463](https://github.com/gridstack/gridstack.js/pull/3463) drop target goes by the grabbed handle (min 10%) rather than the whole widget, so widgets dragged by a header follow the mouse more closely
155155
* feat: a hidden (collapsed) sub-grid works like a folder: the widget goes in (as its first widget) from its middle, and beside it near its edges, so you can insert between collapsed ones
156156
* fix: `ui-droppable-over` class is now removed when the widget leaves or drops
157+
* fix: [#3198](https://github.com/gridstack/gridstack.js/issues/3198) a widget taller (or wider) than a sub-grid can now be dropped into it
157158

158159
## 14.1.0 (2026-11-04)
159160
* feat: [#3451](https://github.com/gridstack/gridstack.js/pull/3451), [#3452](https://github.com/gridstack/gridstack.js/pull/3452) dragging between grids now goes by how much of the item is over a grid (like jquery-ui's `intersect` before v6) rather than where the cursor is. Also make it possible to insert above a nested grid even when parent grid overlapps exactly.

‎spec/regression-spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,16 @@ describe('regression >', () => {
13521352
expect(DDManager.dropElement).toBeUndefined();
13531353
});
13541354

1355+
it('goes into a sub-grid shorter than the item once it spans its whole height #3198', () => {
1356+
cellBox = box(100, 100, 400, 50); // half the item's height
1357+
moveTo(150, 300); // out to the parent
1358+
expect(DDManager.dropElement).toBe(mainDrop());
1359+
moveTo(150, 120); // over 60% of its height
1360+
expect(DDManager.dropElement).toBe(mainDrop());
1361+
moveTo(150, 75); // over all of it (half the item): as much as can fit
1362+
expect(DDManager.dropElement).toBe(subDrop());
1363+
});
1364+
13551365
it('enters the outermost grid once half of the item is over it', () => {
13561366
leaveAll();
13571367
moveTo(150, 30); // 30%

‎src/dd-droppable.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt
136136
}
137137
}
138138

139-
/** @internal fraction (0-1) of the smaller box that is covered by the intersection of the two */
139+
/**
140+
* @internal how much (0-1) the two boxes overlap, each way by the smaller of their sides there - so a tall narrow item
141+
* spanning a short wide sub-grid's whole height is all over it (as much as can fit) rather than stuck at their height ratio.
142+
* Same as the part of the smaller box covered, when one box is no bigger than the other either way.
143+
*/
140144
public static overlap(a: Box, b: Box): number {
141145
const w = Math.min(a.right, b.right) - Math.max(a.left, b.left);
142146
const h = Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top);
143-
const area = Math.min(a.width * a.height, b.width * b.height);
144-
return w > 0 && h > 0 && area > 0 ? (w * h) / area : 0;
147+
const sw = Math.min(a.width, b.width), sh = Math.min(a.height, b.height);
148+
return w > 0 && h > 0 && sw > 0 && sh > 0 ? (w / sw) * (h / sh) : 0;
145149
}
146150

147151
/** @internal if a's center is inside b, away from its edges (see hiddenEdge) */

0 commit comments

Comments
 (0)