Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d75627d

Browse files
committed
NaN inf loop when using cellHeight rem/em
* fix gridstack#2357 and added demo for it
1 parent 8112402 commit d75627d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Change log
9393
## 8.2.1-dev (TBD)
9494
* fix [#2349](https://github.com/gridstack/gridstack.js/issues/2349) grid NoMove vs item NoMove support
9595
* fix [#2352](https://github.com/gridstack/gridstack.js/issues/2352) .ui-draggable-dragging z-index for modal dialogs
96+
* fix [#2357](https://github.com/gridstack/gridstack.js/issues/2357) NaN inf loop when using cellHeight rem/em
9697

9798
## 8.2.1 (2023-05-26)
9899
* fix: make sure `removeNode()` uses internal _id (unique) and not node itself (since we clone those often)

spec/e2e/html/2357_rem.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<title>REM demo</title>
4+
<link rel="stylesheet" href="../../../demo.css"/>
5+
<script src="../../../dist/gridstack-all.js"></script>
6+
</head>
7+
<body>
8+
<div class="grid-stack"></div>
9+
<script type="text/javascript">
10+
let items = [
11+
{x: 0, y: 0},
12+
{x: 1, y: 0},
13+
];
14+
let count = 0;
15+
items.forEach(d => d.content = String(count++));
16+
17+
let grid = GridStack.init({
18+
// cellHeight: '90',
19+
cellHeight: '8rem',
20+
}).load(items);
21+
</script>
22+
</body>
23+
</html>

src/gridstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ export class GridStack {
732732
// else get first cell height
733733
let el = this.el.querySelector('.' + this.opts.itemClass) as HTMLElement;
734734
if (el) {
735-
let height = Utils.toNumber(el.getAttribute('gs-h'));
735+
let height = Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
736736
return Math.round(el.offsetHeight / height);
737737
}
738738
// else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)

0 commit comments

Comments
 (0)