Skip to content

Commit 0c80fe8

Browse files
authored
Merge pull request #2418 from adumesny/master
more fitToContent fixes
2 parents 69e4a57 + 97eb4ee commit 0c80fe8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/gridstack.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,8 +1268,11 @@ export class GridStack {
12681268
if (!height) return; // 0 when hidden, skip
12691269
const item = el.querySelector(GridStack.resizeToContentParent);
12701270
if (!item) return;
1271+
const child = item.firstElementChild;
1272+
// NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1273+
if (!child) { console.log(`Error: resizeToContent() '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`); return; }
12711274
const itemH = item.clientHeight; // available height to our child (minus border, padding...)
1272-
const wantedH = (item.firstChild as Element)?.getBoundingClientRect().height || itemH; // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
1275+
const wantedH = child.getBoundingClientRect().height || itemH;
12731276
if (itemH === wantedH) return;
12741277
height += wantedH - itemH;
12751278
const cell = this.getCellHeight();
@@ -1639,9 +1642,12 @@ export class GridStack {
16391642
if (n) {
16401643
if (Utils.shouldFitToContent(n)) this.resizeToContentCheck(n.el);
16411644
} else {
1642-
this.engine.nodes.forEach(n => {
1645+
const nodes = [...this.engine.nodes]; // in case order changes while resizing one
1646+
this.batchUpdate();
1647+
nodes.forEach(n => {
16431648
if (Utils.shouldFitToContent(n)) this.resizeToContentCheck(n.el);
16441649
});
1650+
this.batchUpdate(false);
16451651
}
16461652
if (this._gsEventHandler['resizeContent']) this._gsEventHandler['resizeContent'](null, n ? [n] : this.engine.nodes);
16471653
}, delay ? 300 + 10 : 0);

0 commit comments

Comments
 (0)