Skip to content

Commit e852c2a

Browse files
committed
- Avoid reflow via setting minRow
1 parent 1b8b503 commit e852c2a

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
@@ -1597,7 +1597,9 @@ export class GridStack {
15971597
if (!cellHeight) return this;
15981598

15991599
// check for css min height (non nested grid). TODO: support mismatch, say: min % while unit is px.
1600-
if (!parent) {
1600+
// If `minRow` was applied, don't override it with this check, and avoid performance issues
1601+
// (reflows) using `getComputedStyle`
1602+
if (!parent && !this.opts.minRow) {
16011603
const cssMinHeight = Utils.parseHeight(getComputedStyle(this.el)['minHeight']);
16021604
if (cssMinHeight.h > 0 && cssMinHeight.unit === unit) {
16031605
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)