Skip to content

Commit

Permalink
Merge pull request #2418 from adumesny/master
Browse files Browse the repository at this point in the history
more fitToContent fixes
  • Loading branch information
adumesny authored Aug 23, 2023
2 parents 69e4a57 + 97eb4ee commit 0c80fe8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,11 @@ export class GridStack {
if (!height) return; // 0 when hidden, skip
const item = el.querySelector(GridStack.resizeToContentParent);
if (!item) return;
const child = item.firstElementChild;
// NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
if (!child) { console.log(`Error: resizeToContent() '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`); return; }
const itemH = item.clientHeight; // available height to our child (minus border, padding...)
const wantedH = (item.firstChild as Element)?.getBoundingClientRect().height || itemH; // NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
const wantedH = child.getBoundingClientRect().height || itemH;
if (itemH === wantedH) return;
height += wantedH - itemH;
const cell = this.getCellHeight();
Expand Down Expand Up @@ -1639,9 +1642,12 @@ export class GridStack {
if (n) {
if (Utils.shouldFitToContent(n)) this.resizeToContentCheck(n.el);
} else {
this.engine.nodes.forEach(n => {
const nodes = [...this.engine.nodes]; // in case order changes while resizing one
this.batchUpdate();
nodes.forEach(n => {
if (Utils.shouldFitToContent(n)) this.resizeToContentCheck(n.el);
});
this.batchUpdate(false);
}
if (this._gsEventHandler['resizeContent']) this._gsEventHandler['resizeContent'](null, n ? [n] : this.engine.nodes);
}, delay ? 300 + 10 : 0);
Expand Down

0 comments on commit 0c80fe8

Please sign in to comment.