Skip to content

Commit 850d6b1

Browse files
committed
fix _updateContainerHeight() to use height
rather than min-height again (apart for nested grids which need it) and partial getComputedStyle CSS minHeight support
1 parent 1ae1481 commit 850d6b1

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

demo/nested_advanced.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<title>Advance Nested grids demo</title>
88
<link rel="stylesheet" href="demo.css"/>
99
<link rel="stylesheet" href="../dist/gridstack-extra.min.css"/> <!-- required for [2-11] column of sub-grids -->
10+
<!-- test using CSS rather than minRow -->
11+
<style type="text/css">
12+
.container-fluid > .grid-stack { min-height: 250px}
13+
</style>
1014
<script src="../dist/gridstack-all.js"></script>
1115
</head>
1216
<body>

src/gridstack.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,30 +1489,34 @@ export class GridStack {
14891489
/** @internal */
14901490
protected _updateContainerHeight(): GridStack {
14911491
if (!this.engine || this.engine.batchMode) return this;
1492-
let row = this.getRow() + this._extraDragRow; // checks for minRow already
1493-
// check for css min height
1494-
// Note: we don't handle %,rem correctly so comment out, beside we don't need need to create un-necessary
1495-
// rows as the CSS will make us bigger than our set height if needed... not sure why we had this.
1496-
// let cssMinHeight = parseInt(getComputedStyle(this.el)['min-height']);
1497-
// if (cssMinHeight > 0) {
1498-
// let minRow = Math.round(cssMinHeight / this.getCellHeight(true));
1499-
// if (row < minRow) {
1500-
// row = minRow;
1501-
// }
1502-
// }
1492+
const parent = this.parentGridItem;
1493+
let row = this.getRow() + this._extraDragRow; // this checks for minRow already
1494+
const cellHeight = this.opts.cellHeight as number;
1495+
const unit = this.opts.cellHeightUnit;
1496+
if (!cellHeight) return this;
1497+
1498+
// check for css min height (non nested grid). TODO: support mismatch, say: min % while unit is px.
1499+
if (!parent) {
1500+
const cssMinHeight = Utils.parseHeight(getComputedStyle(this.el)['minHeight']);
1501+
if (cssMinHeight.h > 0 && cssMinHeight.unit === unit) {
1502+
const minRow = Math.floor(cssMinHeight.h / cellHeight);
1503+
if (row < minRow) {
1504+
row = minRow;
1505+
}
1506+
}
1507+
}
1508+
15031509
this.el.setAttribute('gs-current-row', String(row));
1504-
if (row === 0) {
1505-
this.el.style.removeProperty('min-height');
1506-
} else {
1507-
let cellHeight = this.opts.cellHeight as number;
1508-
let unit = this.opts.cellHeightUnit;
1509-
if (!cellHeight) return this;
1510-
this.el.style.minHeight = row * cellHeight + unit;
1510+
this.el.style.removeProperty('min-height');
1511+
this.el.style.removeProperty('height');
1512+
if (row) {
1513+
// nested grids have 'insert:0' to fill the space of parent by default, but we may be taller so use min-height for possible scrollbars
1514+
this.el.style[parent ? 'minHeight' : 'height'] = row * cellHeight + unit;
15111515
}
15121516

15131517
// if we're a nested grid inside an sizeToContent item, tell it to resize itself too
1514-
if (this.parentGridItem && !this.parentGridItem.grid.engine.batchMode && Utils.shouldSizeToContent(this.parentGridItem)) {
1515-
this.parentGridItem.grid.resizeToContentCheck(this.parentGridItem.el);
1518+
if (parent && !parent.grid.engine.batchMode && Utils.shouldSizeToContent(parent)) {
1519+
parent.grid.resizeToContentCheck(parent.el);
15161520
}
15171521

15181522
return this;

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module.exports = {
55
'gridstack-all': './src/gridstack.ts',
66
},
77
mode: 'production', // production vs development
8-
devtool: 'source-map',
9-
// devtool: 'eval-source-map', // for best (large .js) debugging. see https://survivejs.com/webpack/building/source-maps/
8+
// devtool: 'source-map',
9+
devtool: 'eval-source-map', // for best (large .js) debugging. see https://survivejs.com/webpack/building/source-maps/
1010
module: {
1111
rules: [
1212
{

0 commit comments

Comments
 (0)