Skip to content

Commit 6d0e75c

Browse files
authored
Merge pull request #3054 from iongroup/fix/reflow
Avoid reflows via explicitly setting minRow
2 parents c487581 + e852c2a commit 6d0e75c

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

doc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ gridstack.js API
116116
- `marginBottom`: numberOrString
117117
- `marginLeft`: numberOrString
118118
- `maxRow` - maximum rows amount. Default is `0` which means no max.
119-
- `minRow` - minimum rows amount which is handy to prevent grid from collapsing when empty. Default is `0`. You can also do this with `min-height` CSS attribute on the grid div in pixels, which will round to the closest row.
119+
- `minRow` - minimum rows amount which is handy to prevent grid from collapsing when empty. Default is `0`. When no set set, the `min-height` CSS attribute on the grid div (in pixels) can be used as well, which will round to the closest row.
120120
- `nonce` - If you are using a nonce-based Content Security Policy, pass your nonce here and
121121
GridStack will add it to the `<style>` elements it creates.
122122
- `placeholderClass` - class for placeholder (default: `'grid-stack-placeholder'`)

src/gridstack.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,9 @@ export class GridStack {
16031603
if (!cellHeight) return this;
16041604

16051605
// check for css min height (non nested grid). TODO: support mismatch, say: min % while unit is px.
1606-
if (!parent) {
1606+
// If `minRow` was applied, don't override it with this check, and avoid performance issues
1607+
// (reflows) using `getComputedStyle`
1608+
if (!parent && !this.opts.minRow) {
16071609
const cssMinHeight = Utils.parseHeight(getComputedStyle(this.el)['minHeight']);
16081610
if (cssMinHeight.h > 0 && cssMinHeight.unit === unit) {
16091611
const minRow = Math.floor(cssMinHeight.h / cellHeight);

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ export interface GridStackOptions {
217217
/** maximum rows amount. Default? is 0 which means no maximum rows */
218218
maxRow?: number;
219219

220-
/** minimum rows amount. Default is `0`. You can also do this with `min-height` CSS attribute
221-
* on the grid div in pixels, which will round to the closest row.
220+
/** minimum rows amount which is handy to prevent grid from collapsing when empty. Default is `0`.
221+
* When no set set, the `min-height` CSS attribute on the grid div (in pixels) can be used as well, which will round to the closest row.
222222
*/
223223
minRow?: number;
224224

0 commit comments

Comments
 (0)