Skip to content

Commit

Permalink
NaN inf loop when using cellHeight rem/em
Browse files Browse the repository at this point in the history
* fix gridstack#2357 and added demo for it
  • Loading branch information
adumesny committed Jun 12, 2023
1 parent 8112402 commit d75627d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Change log
## 8.2.1-dev (TBD)
* fix [#2349](https://github.com/gridstack/gridstack.js/issues/2349) grid NoMove vs item NoMove support
* fix [#2352](https://github.com/gridstack/gridstack.js/issues/2352) .ui-draggable-dragging z-index for modal dialogs
* fix [#2357](https://github.com/gridstack/gridstack.js/issues/2357) NaN inf loop when using cellHeight rem/em

## 8.2.1 (2023-05-26)
* fix: make sure `removeNode()` uses internal _id (unique) and not node itself (since we clone those often)
Expand Down
23 changes: 23 additions & 0 deletions spec/e2e/html/2357_rem.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<head>
<title>REM demo</title>
<link rel="stylesheet" href="../../../demo.css"/>
<script src="../../../dist/gridstack-all.js"></script>
</head>
<body>
<div class="grid-stack"></div>
<script type="text/javascript">
let items = [
{x: 0, y: 0},
{x: 1, y: 0},
];
let count = 0;
items.forEach(d => d.content = String(count++));

let grid = GridStack.init({
// cellHeight: '90',
cellHeight: '8rem',
}).load(items);
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ export class GridStack {
// else get first cell height
let el = this.el.querySelector('.' + this.opts.itemClass) as HTMLElement;
if (el) {
let height = Utils.toNumber(el.getAttribute('gs-h'));
let height = Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
return Math.round(el.offsetHeight / height);
}
// else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)
Expand Down

0 comments on commit d75627d

Please sign in to comment.