Skip to content

Commit 381f2fb

Browse files
authored
Merge pull request #1752 from adumesny/master
Util getScrollParent() -> getScrollElement()
2 parents 80a7092 + c391330 commit 381f2fb

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

doc/CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8+
- [4.2.2-dev](#422-dev)
89
- [4.2.2 (2021-4-23)](#422-2021-4-23)
910
- [4.2.1 (2021-4-18)](#421-2021-4-18)
1011
- [4.2.0 (2021-4-11)](#420-2021-4-11)
@@ -55,6 +56,11 @@ Change log
5556
- [v0.1.0 (2014-11-18)](#v010-2014-11-18)
5657

5758
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
59+
## 4.2.2-dev
60+
61+
- `Utils.getScrollParent()` -> `getScrollElement()` rename
62+
- fix [#1745](https://github.com/gridstack/gridstack.js/issues/1745) digression on scrolling in v4.2.1. Thanks [@Manfred-on-github](https://github.com/Manfred-on-github) for fixing your prev change.
63+
5864
## 4.2.2 (2021-4-23)
5965

6066
- fix [#1684](https://github.com/gridstack/gridstack.js/issues/1684) [#1550](https://github.com/gridstack/gridstack.js/issues/1550) mac Safari H5 draggable broken in 4.0.1. Thanks [@wurambo](https://github.com/wurambo)

spec/utils-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('gridstack utils', function() {
123123
expect(el.style.position).toEqual('');
124124

125125
// bogus test
126-
expect(Utils.getScrollParent(el)).not.toBe(null);
126+
expect(Utils.getScrollElement(el)).not.toBe(null);
127127
// bogus test
128128
Utils.updateScrollPosition(el, {top: 20}, 10);
129129
});

src/h5/dd-resizable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
154154
/** @internal */
155155
private _resizeStart(event: MouseEvent): DDResizable {
156156
this.originalRect = this.el.getBoundingClientRect();
157-
this.scrollEl = Utils.getScrollParent(this.el);
157+
this.scrollEl = Utils.getScrollElement(this.el);
158158
this.scrollY = this.scrollEl.scrollTop;
159159
this.startEvent = event;
160160
this._setupHelper();

src/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,16 @@ export class Utils {
291291
}
292292
}
293293

294-
/** @internal */
295-
static getScrollParent(el: HTMLElement): HTMLElement {
296-
if (el === null) return document.scrollingElement as HTMLElement;
294+
/** @internal returns the passed element if scrollable, else the closest parent that will, up to the entire document scrolling element */
295+
static getScrollElement(el?: HTMLElement): HTMLElement {
296+
if (!el) return document.scrollingElement as HTMLElement;
297297
const style = getComputedStyle(el);
298298
const overflowRegex = /(auto|scroll)/;
299299

300300
if (overflowRegex.test(style.overflow + style.overflowY)) {
301301
return el;
302302
} else {
303-
return this.getScrollParent(el.parentElement);
303+
return this.getScrollElement(el.parentElement);
304304
}
305305
}
306306

@@ -317,7 +317,7 @@ export class Utils {
317317
// to get entire widget on screen
318318
let offsetDiffDown = rect.bottom - innerHeightOrClientHeight;
319319
let offsetDiffUp = rect.top;
320-
let scrollEl = this.getScrollParent(el);
320+
let scrollEl = this.getScrollElement(el);
321321
if (scrollEl !== null) {
322322
let prevScroll = scrollEl.scrollTop;
323323
if (rect.top < 0 && distance < 0) {
@@ -349,7 +349,7 @@ export class Utils {
349349
* @param distance Distance from the V edges to start scrolling
350350
*/
351351
static updateScrollResize(event: MouseEvent, el: HTMLElement, distance: number): void {
352-
const scrollEl = this.getScrollParent(el);
352+
const scrollEl = this.getScrollElement(el);
353353
const height = scrollEl.clientHeight;
354354
const offsetTop = scrollEl.getBoundingClientRect().top;
355355
const pointerPosY = event.clientY - offsetTop;

0 commit comments

Comments
 (0)