Skip to content

Commit ebf982b

Browse files
authored
Merge pull request #1877 from adumesny/master
fix resize when padding is large vs cellHeight
2 parents 8918171 + 8dd5ded commit ebf982b

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Change log
6666
## 4.3.0-dev (TBD)
6767
* fix [#1868](https://github.com/gridstack/gridstack.js/issues/1868) prevent swap during resize
6868
* fix [#1849](https://github.com/gridstack/gridstack.js/issues/1849) [#1816](https://github.com/gridstack/gridstack.js/issues/1816) save highest resolution in 1 column mode
69+
* fix [#1855](https://github.com/gridstack/gridstack.js/issues/1855) fix resize when padding is large vs cellHeight
6970

7071
## 4.3.0 (2021-10-15)
7172
* you can now swap items of different width if they are the same row/height. Thanks to [spektrummedia](http://spektrummedia.com) for sponsoring it.

src/gridstack-dd.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,19 @@ GridStack.prototype._leave = function(this: GridStack, el: GridItemHTMLElement,
535535
GridStack.prototype._dragOrResize = function(this: GridStack, el: GridItemHTMLElement, event: Event, ui: DDUIData, node: GridStackNode, cellWidth: number, cellHeight: number) {
536536
let p = {...node._orig}; // could be undefined (_isExternal) which is ok (drag only set x,y and w,h will default to node value)
537537
let resizing: boolean;
538-
const mLeft = this.opts.marginLeft as number,
538+
let mLeft = this.opts.marginLeft as number,
539539
mRight = this.opts.marginRight as number,
540540
mTop = this.opts.marginTop as number,
541541
mBottom = this.opts.marginBottom as number;
542542

543+
// if margins (which are used to pass mid point by) are large relative to cell height/width, reduce them down #1855
544+
let mHeight = Math.round(cellHeight * 0.1),
545+
mWidth = Math.round(cellWidth * 0.1);
546+
mLeft = Math.min(mLeft, mWidth);
547+
mRight = Math.min(mRight, mWidth);
548+
mTop = Math.min(mTop, mHeight);
549+
mBottom = Math.min(mBottom, mHeight);
550+
543551
if (event.type === 'drag') {
544552
if (node._temporaryRemoved) return; // handled by dropover
545553
let distance = ui.position.top - node._prevYPix;

src/h5/dd-resizable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
156156
this.originalRect = this.el.getBoundingClientRect();
157157
this.scrollEl = Utils.getScrollElement(this.el);
158158
this.scrollY = this.scrollEl.scrollTop;
159+
this.scrolled = 0;
159160
this.startEvent = event;
160161
this._setupHelper();
161162
this._applyChange();

0 commit comments

Comments
 (0)