Skip to content

Commit 1c5e97f

Browse files
authored
Merge pull request #1912 from adumesny/master
no longer force rows for min-height
2 parents 7aa3805 + a7f4214 commit 1c5e97f

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

demo/nested.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
}
1616
/* make nested grid take almost all space (need some to tell them apart) so items inside can have similar to external size+margin */
1717
.grid-stack > .grid-stack-item.grid-stack-nested > .grid-stack-item-content {
18-
inset: 2px;
18+
/* inset: 0 2px; not IE */
19+
top: 0;
20+
bottom: 0;
21+
left: 2px;
22+
right: 2px;
1923
}
2024
/* make nested grid take entire item content */
2125
.grid-stack-item-content .grid-stack {
@@ -52,7 +56,7 @@ <h1>Nested grids demo</h1>
5256
let count = 0;
5357
[...sub1, ...sub2].forEach(d => d.content = String(count++));
5458
let subOptions = {
55-
cellHeight: 50,
59+
cellHeight: 50, // should be 50 - top/bottom
5660
column: 'auto', // size to match container. make sure to include gridstack-extra.min.css
5761
acceptWidgets: true, // will accept .grid-stack-item by default
5862
margin: 5,

src/gridstack.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,15 @@ export class GridStack {
600600
(!forcePixel || !this.opts.cellHeightUnit || this.opts.cellHeightUnit === 'px')) {
601601
return this.opts.cellHeight as number;
602602
}
603-
// else do entire grid and # of rows
604-
// or get first cell height ?
605-
// let el = this.el.querySelector('.' + this.opts.itemClass) as HTMLElement;
606-
// let height = Utils.toNumber(el.getAttribute('gs-h'));
607-
// return Math.round(el.offsetHeight / height);
608-
return Math.round(this.el.getBoundingClientRect().height) / parseInt(this.el.getAttribute('gs-current-row'));
603+
// else get first cell height
604+
let el = this.el.querySelector('.' + this.opts.itemClass) as HTMLElement;
605+
if (el) {
606+
let height = Utils.toNumber(el.getAttribute('gs-h'));
607+
return Math.round(el.offsetHeight / height);
608+
}
609+
// else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)
610+
let rows = parseInt(this.el.getAttribute('gs-current-row'));
611+
return rows ? Math.round(this.el.getBoundingClientRect().height / rows) : this.opts.cellHeight as number;
609612
}
610613

611614
/**
@@ -1238,13 +1241,15 @@ export class GridStack {
12381241
if (!this.engine || this.engine.batchMode) return this;
12391242
let row = this.getRow() + this._extraDragRow; // checks for minRow already
12401243
// check for css min height
1241-
let cssMinHeight = parseInt(getComputedStyle(this.el)['min-height']);
1242-
if (cssMinHeight > 0) {
1243-
let minRow = Math.round(cssMinHeight / this.getCellHeight(true));
1244-
if (row < minRow) {
1245-
row = minRow;
1246-
}
1247-
}
1244+
// Note: we don't handle %,rem correctly so comment out, beside we don't need need to create un-necessary
1245+
// rows as the CSS will make us bigger than our set height if needed... not sure why we had this.
1246+
// let cssMinHeight = parseInt(getComputedStyle(this.el)['min-height']);
1247+
// if (cssMinHeight > 0) {
1248+
// let minRow = Math.round(cssMinHeight / this.getCellHeight(true));
1249+
// if (row < minRow) {
1250+
// row = minRow;
1251+
// }
1252+
// }
12481253
this.el.setAttribute('gs-current-row', String(row));
12491254
if (row === 0) {
12501255
this.el.style.removeProperty('height');

0 commit comments

Comments
 (0)