Skip to content

Commit 417fa0b

Browse files
authored
Merge pull request #3252 from adumesny/master
scroll fix inside parent
2 parents 41f94d1 + 58f518a commit 417fa0b

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

demo/two.html

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@
1010
<link rel="stylesheet" href="demo.css"/>
1111
<style type="text/css">
1212
.with-lines { border: 1px dotted #777}
13+
.scroll-container {
14+
max-height: 500px;
15+
overflow-y: auto;
16+
border: 2px solid #aaa;
17+
border-radius: 4px;
18+
padding: 10px;
19+
}
1320
</style>
1421

1522
<script src="../dist/gridstack-all.js"></script>
1623
</head>
1724
<body>
1825
<div class="container-fluid">
19-
<h1>Two grids demo</h1>
20-
<p>Two grids, one floating one not, showing drag&drop from sidebar and between grids.
26+
<h1>Two grids demo, with scroll containers</h1>
27+
<p>Two grids, one floating one not, showing drag&drop from sidebar and between grids. Using scoll containers to test.
2128
<br>New v10.2: use 'Esc' to cancel any move/resize. Use 'r' to rotate as you drag.</p>
2229

2330
<div class="row">
@@ -51,11 +58,14 @@ <h1>Two grids demo</h1>
5158
<div class="col-md-6">
5259
<a onClick="toggleFloat(this, 0)" class="btn btn-primary" href="#">float: true</a>
5360
<a onClick="compact(0)" class="btn btn-primary" href="#">Compact</a>
54-
<div class="grid-stack" id="left_grid"></div>
61+
<div class="scroll-container">
62+
<div class="grid-stack" id="left_grid"></div>
63+
</div>
5564
</div>
5665
<div class="col-md-6">
5766
<a onClick="toggleFloat(this, 1)" class="btn btn-primary" href="#">float: false</a>
5867
<a onClick="compact(1)" class="btn btn-primary" href="#">Compact</a>
68+
page scroll test
5969
<div class="grid-stack" id="right_grid"></div>
6070
</div>
6171
</div>
@@ -68,7 +78,7 @@ <h1>Two grids demo</h1>
6878
{x: 1, y: 1}, // intentional overlap to test collision on load
6979
{x: 3, y: 1},
7080
{x: 2, y: 3, w: 3, maxW: 3, content: 'has maxW=3'},
71-
{x: 2, y: 5}
81+
{x: 2, y: 5, h:20}
7282
];
7383
items.forEach((item, i) => item.content = item.content || String(i));
7484

doc/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Change log
139139
## 12.4.3 (TBD)
140140
* fix: [#3237](https://github.com/gridstack/gridstack.js/pull/3237) updateOptions() fixes for columnOpts, maxRow. load() not cloning
141141
* fix: [#3241](https://github.com/gridstack/gridstack.js/pull/3241) drifting rounding issue when cellHeight is small/fraction
142-
* fix: [#2188](https://github.com/gridstack/gridstack.js/issues/2188) scroll speed too high
142+
* fix: [#2188](https://github.com/gridstack/gridstack.js/issues/2188), [#2074](https://github.com/gridstack/gridstack.js/issues/2074) scroll speed too high, not animating, not using container parent
143143

144144
## 12.4.2 (2025-12-26)
145145
* regression: [#3214](https://github.com/gridstack/gridstack.js/issues/3214) touch device with real mouse event fix (caused by #3191 in last release)

src/gridstack.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,9 +3035,10 @@ export class GridStack {
30353035
return 0;
30363036
}
30373037

3038-
/** @internal starts or continues auto-scroll when the dragged element is clipped by the scroll container */
3038+
/** @internal starts or continues auto-scroll when the dragged element is clipped by the scroll container.
3039+
* Uses the grid's own element to find the scroll container so external/sidebar drags work too (#2074). */
30393040
protected _updateScrollPosition(el: HTMLElement): void {
3040-
const scrollEl = Utils.getScrollElement(el);
3041+
const scrollEl = Utils.getScrollElement(this.el);
30413042
if (!scrollEl) return;
30423043
this._autoScrollEl = el;
30433044
this._autoScrollContainer = scrollEl;
@@ -3059,12 +3060,10 @@ export class GridStack {
30593060
const clipping = this._getClipping(el, scrollEl);
30603061
if (clipping === 0) { this._stopScrolling(); return; }
30613062

3062-
const scrollRect = scrollEl.getBoundingClientRect();
30633063
const viewportH = window.innerHeight || document.documentElement.clientHeight;
3064-
const containerH = Math.min(scrollRect.height, viewportH);
3065-
const maxSpeed = Math.max(containerH / 75, 2);
3064+
const maxSpeed = Math.max(viewportH / 75, 4);
30663065
const absPx = Math.abs(clipping);
3067-
const speed = Math.min(absPx * 0.3, maxSpeed);
3066+
const speed = Math.min(absPx * 0.6, maxSpeed);
30683067
const scrollAmount = clipping > 0 ? speed : -speed;
30693068

30703069
const prevScroll = scrollEl.scrollTop;

0 commit comments

Comments
 (0)