Skip to content

Commit 84cec8d

Browse files
committed
Select scrollable parent
1 parent 5ba15dc commit 84cec8d

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

src/gridstack-dd.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
342342
// variables used/cashed between the 3 start/move/end methods, in addition to node passed above
343343
let cellWidth: number;
344344
let cellHeight: number;
345-
let minRow: number;
346345

347346
/** called when item starts moving/resizing */
348347
let onStartMoving = (event: Event, ui: DDUIData): void => {
@@ -353,9 +352,6 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
353352
this._gsEventHandler[event.type](event, target);
354353
}
355354

356-
// Saving `minRow`
357-
minRow = this.opts.minRow;
358-
359355
this.engine.cleanNodes();
360356
this.engine.beginUpdate(node);
361357
cellWidth = this.cellWidth();
@@ -426,17 +422,8 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
426422
if (node._lastTriedX === x && node._lastTriedY === y) return;
427423
} else if (event.type === 'resize') {
428424
if (x < 0) return;
429-
// Addin an extra row if the item it's at the bottom of the layout
430-
if (node.y+node.h >= this.getRow()-1) {
431-
this.opts.minRow = this.getRow() + 1;
432-
this._updateContainerHeight();
433-
}
434-
435425
// Scrolling page if needed
436426
Utils.updateScrollResize(event as MouseEvent, el, cellHeight);
437-
// Restore minRow
438-
this.opts.minRow = minRow;
439-
440427
w = Math.round(ui.size.width / cellWidth);
441428
h = Math.round(ui.size.height / cellHeight);
442429
if (w === node.w && h === node.h) return;

src/h5/dd-resizable.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
4242
/** @internal */
4343
private scrolled: number;
4444
/** @internal */
45+
private scrollEl: HTMLElement;
46+
/** @internal */
4547
private startEvent: MouseEvent;
4648
/** @internal value saved in the same order as _originStyleProp[] */
4749
private elOriginStyleVal: string[];
@@ -157,8 +159,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
157159
/** @internal */
158160
private _resizeStart(event: MouseEvent): DDResizable {
159161
this.originalRect = this.el.getBoundingClientRect();
160-
const scrollEl = Utils.getScrollParent(this.el);
161-
this.scrollY = scrollEl ? scrollEl.scrollTop : 0;
162+
this.scrollEl = Utils.getScrollParent(this.el);
163+
this.scrollY = this.scrollEl.scrollTop;
162164
this.startEvent = event;
163165
this._setupHelper();
164166
this._applyChange();
@@ -173,8 +175,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
173175

174176
/** @internal */
175177
private _resizing(event: MouseEvent, dir: string): DDResizable {
176-
const scrollEl = Utils.getScrollParent(this.el);
177-
this.scrolled = scrollEl ? (scrollEl.scrollTop - this.scrollY) : this.scrollY;
178+
this.scrolled = this.scrollEl.scrollTop - this.scrollY;
178179
this.temporalRect = this._getChange(event, dir);
179180
this._applyChange();
180181
const ev = DDUtils.initEvent<MouseEvent>(event, { type: 'resize', target: this.el });
@@ -303,7 +304,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
303304

304305
/** @internal */
305306
private _ui = (): DDUIData => {
306-
const containmentRect = this.el.parentElement.getBoundingClientRect();
307+
const containmentEl = this.el.parentElement;
308+
const containmentRect = containmentEl.getBoundingClientRect();
307309
const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out.
308310
width: this.originalRect.width,
309311
height: this.originalRect.height + this.scrolled,

src/utils.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ export class Utils {
280280

281281
/** @internal */
282282
static getScrollParent(el: HTMLElement): HTMLElement {
283-
let returnEl;
284-
if (el === null) {
285-
returnEl = null;
286-
} else if (el.scrollHeight > el.clientHeight) {
287-
returnEl = el;
283+
if (el === null) return document.documentElement;
284+
const style = getComputedStyle(el);
285+
const overflowRegex = /(auto|scroll)/;
286+
287+
if (overflowRegex.test(style.overflow + style.overflowY)) {
288+
return el;
288289
} else {
289-
returnEl = this.getScrollParent(el.parentElement);
290+
return this.getScrollParent(el.parentElement);
290291
}
291-
return returnEl;
292292
}
293293

294294
/** @internal */
@@ -338,10 +338,7 @@ export class Utils {
338338
* @param distance Distance to scroll
339339
*/
340340
static updateScrollResize(event: MouseEvent, el: HTMLElement, distance: number): void {
341-
let scrollEl = this.getScrollParent(el);
342-
if (!scrollEl ) return;
343-
344-
//const width = scrollEl.clientWidth;
341+
const scrollEl = this.getScrollParent(el);
345342
const height = scrollEl.clientHeight;
346343

347344
const top = event.clientY < distance;

0 commit comments

Comments
 (0)