Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a71495

Browse files
committed
- Avoid reflow via setting minRow
1 parent f467c35 commit 2a71495

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
@@ -115,7 +115,7 @@ gridstack.js API
115115
- `marginBottom`: numberOrString
116116
- `marginLeft`: numberOrString
117117
- `maxRow` - maximum rows amount. Default is `0` which means no max.
118-
- `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.
118+
- `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.
119119
- `nonce` - If you are using a nonce-based Content Security Policy, pass your nonce here and
120120
GridStack will add it to the `<style>` elements it creates.
121121
- `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
@@ -1543,7 +1543,9 @@ export class GridStack {
15431543
if (!cellHeight) return this;
15441544

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

src/types.ts

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

219-
/** minimum rows amount. Default is `0`. You can also do this with `min-height` CSS attribute
220-
* on the grid div in pixels, which will round to the closest row.
219+
/** minimum rows amount which is handy to prevent grid from collapsing when empty. Default is `0`.
220+
* 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.
221221
*/
222222
minRow?: number;
223223

0 commit comments

Comments
 (0)