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

Skip to content

Avoid reflows via explicitly setting minRow #3054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ gridstack.js API
- `marginBottom`: numberOrString
- `marginLeft`: numberOrString
- `maxRow` - maximum rows amount. Default is `0` which means no max.
- `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.
- `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.
- `nonce` - If you are using a nonce-based Content Security Policy, pass your nonce here and
GridStack will add it to the `<style>` elements it creates.
- `placeholderClass` - class for placeholder (default: `'grid-stack-placeholder'`)
Expand Down
4 changes: 3 additions & 1 deletion src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,9 @@ export class GridStack {
if (!cellHeight) return this;

// check for css min height (non nested grid). TODO: support mismatch, say: min % while unit is px.
if (!parent) {
// If `minRow` was applied, don't override it with this check, and avoid performance issues
// (reflows) using `getComputedStyle`
if (!parent && !this.opts.minRow) {
const cssMinHeight = Utils.parseHeight(getComputedStyle(this.el)['minHeight']);
if (cssMinHeight.h > 0 && cssMinHeight.unit === unit) {
const minRow = Math.floor(cssMinHeight.h / cellHeight);
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ export interface GridStackOptions {
/** maximum rows amount. Default? is 0 which means no maximum rows */
maxRow?: number;

/** minimum rows amount. 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.
/** 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.
*/
minRow?: number;

Expand Down