Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resizeToContent JS error with nested grid #2741

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Change log

## 10.3.0-dev (TBD)
* fix: [#2734](https://github.com/gridstack/gridstack.js/bug/2734) rotate() JS error
* fix: [#2739](https://github.com/gridstack/gridstack.js/pull/2739) resizeToContent JS error with nested grid

## 10.3.0 (2024-06-26)
* fix: [#2720](https://github.com/gridstack/gridstack.js/pull/2720) load() now creates widgets in order (used to be reverse due to old collision code)
Expand Down
8 changes: 7 additions & 1 deletion src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,10 +1401,16 @@ export class GridStack {
if (n.subGrid) {
// sub-grid - use their actual row count * their cell height
wantedH = n.subGrid.getRow() * n.subGrid.getCellHeight(true);
} else if (n.subGridOpts?.children?.length) {
// not sub-grid just yet (case above) wait until we do
return;
} else {
// NOTE: clientHeight & getBoundingClientRect() is undefined for text and other leaf nodes. use <div> container!
const child = item.firstElementChild;
if (!child) { console.error(`Error: GridStack.resizeToContent() widget id:${n.id} '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`); return; }
if (!child) {
console.error(`Error: GridStack.resizeToContent() widget id:${n.id} '${GridStack.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
return;
}
wantedH = child.getBoundingClientRect().height || itemH;
}
if (itemH === wantedH) return;
Expand Down