Skip to content

Commit 1d0e843

Browse files
committed
fix for resize with cellHeight in rem/em
* fix for #1356 * `getCellHeight(forcePixel = false)` now take optional arg to get pixel values, which is needed during resize calculations * texting with example with "6em" "6rem" "auto" "70" and "70px"
1 parent 38da670 commit 1d0e843

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

demo/float.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ <h1>Float grid demo</h1>
3434
addEvents(grid);
3535

3636
let items = [
37-
{x: 2, y: 1, width: 1, height: 2},
38-
{x: 2, y: 4, width: 3, height: 1},
37+
{x: 1, y: 1, width: 1, height: 1},
38+
{x: 2, y: 2, width: 3, height: 1},
3939
{x: 4, y: 2, width: 1, height: 1},
4040
{x: 3, y: 1, width: 1, height: 2},
4141
{x: 0, y: 6, width: 2, height: 2}

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Change log
4343
- fix `GridStackOptions` spelling [1359](https://github.com/gridstack/gridstack.js/issues/1359)
4444
- fix remove window resize event when `grid.destroy()` [1369](https://github.com/gridstack/gridstack.js/issues/1369)
4545
- fix nested grid resize [1361](https://github.com/gridstack/gridstack.js/issues/1361)
46+
- fix resize with `cellHeight` '6rem' '6em' not working [1356](https://github.com/gridstack/gridstack.js/issues/1356)
4647

4748
## 2.0.0 (2020-09-07)
4849

src/gridstack.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,9 @@ export class GridStack {
419419
/**
420420
* Gets current cell height.
421421
*/
422-
public getCellHeight(): number {
423-
if (this.opts.cellHeight && this.opts.cellHeight !== 'auto') {
422+
public getCellHeight(forcePixel = false): number {
423+
if (this.opts.cellHeight && this.opts.cellHeight !== 'auto' &&
424+
(!forcePixel || !this.opts.cellHeightUnit || this.opts.cellHeightUnit === 'px')) {
424425
return this.opts.cellHeight as number;
425426
}
426427
// else get first cell height
@@ -1209,7 +1210,7 @@ export class GridStack {
12091210
this.engine.cleanNodes();
12101211
this.engine.beginUpdate(node);
12111212
cellWidth = this.cellWidth();
1212-
cellHeight = this.getCellHeight();
1213+
cellHeight = this.getCellHeight(true); // force pixels for calculations
12131214

12141215
this.placeholder.setAttribute('data-gs-x', target.getAttribute('data-gs-x'));
12151216
this.placeholder.setAttribute('data-gs-y', target.getAttribute('data-gs-y'));
@@ -1222,7 +1223,6 @@ export class GridStack {
12221223
node._beforeDragY = node.y;
12231224
node._prevYPix = ui.position.top;
12241225

1225-
// mineHeight - Each row is cellHeight + margin
12261226
this.dd.resizable(el, 'option', 'minWidth', cellWidth * (node.minWidth || 1));
12271227
this.dd.resizable(el, 'option', 'minHeight', cellHeight * (node.minHeight || 1));
12281228
}

0 commit comments

Comments
 (0)