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

Skip to content

Commit c14aaa2

Browse files
committed
grid option minWidth -> OneColumnSize
* renamed to be much lclearer, added support for old field value (JS only) to not break binary compatibility * fix gridstack#1937
1 parent c6078cd commit c14aaa2

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ v2 is a Typescript rewrite of 1.x, removing all jquery events, using classes and
409409
410410
2. event signatures are generic and not jquery-ui dependent anymore. `gsresizestop` has been removed as `resizestop|dragstop` are now called **after** the DOM attributes have been updated.
411411
412-
3. `oneColumnMode` would trigger when `window.width` < 768px by default. We now check for grid width instead (more correct and supports nesting). You might need to adjust grid `minWidth` or `disableOneColumnMode`.
412+
3. `oneColumnMode` would trigger when `window.width` < 768px by default. We now check for grid width instead (more correct and supports nesting). You might need to adjust grid `oneColumnSize` or `disableOneColumnMode`.
413413
414414
**Note:** 2.x no longer support legacy IE11 and older due to using more compact ES6 output and typecsript native code. You will need to stay at 1.x
415415

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Change log
7070

7171
## 5.0.0-dev (TBD)
7272
* add `GridStack.registerEngine()` to let user use their own custom layout engine subclass. Thank you [Thomas] for sponsoring it.
73+
* grid option `minWidth` is now `oneColumnSize` to make it clearer, but old field will still work (JS only) for a while
7374

7475
## 5.0.0 (2022-01-10)
7576
* add [#992](https://github.com/gridstack/gridstack.js/issues/992) support dragging into and out of nested grids from parents! Thank you [@arclogos132](https://github.com/arclogos132) for sponsoring it.

spec/gridstack-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ describe('gridstack', function() {
527527
expect(grid.getColumn()).toBe(1);
528528
});
529529
it('should go to 1 column with large minW', function() {
530-
let grid = GridStack.init({minWidth: 1000});
530+
let grid = GridStack.init({oneColumnSize: 1000});
531531
expect(grid.getColumn()).toBe(1);
532532
});
533533
it('should stay at 12 with minW', function() {
534-
let grid = GridStack.init({minWidth: 300});
534+
let grid = GridStack.init({oneColumnSize: 300});
535535
expect(grid.getColumn()).toBe(12);
536536
});
537537
it('should stay at 12 column', function() {

src/gridstack.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const GridDefaults: GridStackOptions = {
5656
cellHeightThrottle: 100,
5757
margin: 10,
5858
auto: true,
59-
minWidth: 768,
59+
oneColumnSize: 768,
6060
float: false,
6161
staticGrid: false,
6262
animate: true,
@@ -261,6 +261,12 @@ export class GridStack {
261261
if (opts.column === 'auto') {
262262
delete opts.column;
263263
}
264+
// 'minWidth' legacy support in 5.1
265+
let anyOpts = opts as any;
266+
if (anyOpts.minWidth !== undefined) {
267+
opts.oneColumnSize = opts.oneColumnSize || anyOpts.minWidth;
268+
delete anyOpts.minWidth;
269+
}
264270

265271
// elements attributes override any passed options (like CSS style) - merge the two together
266272
let defaults: GridStackOptions = {...Utils.cloneDeep(GridDefaults),
@@ -292,7 +298,7 @@ export class GridStack {
292298
this.initMargin(); // part of settings defaults...
293299

294300
// Now check if we're loading into 1 column mode FIRST so we don't do un-necessary work (like cellHeight = width / 12 then go 1 column)
295-
if (this.opts.column !== 1 && !this.opts.disableOneColumnMode && this._widthOrContainer() <= this.opts.minWidth) {
301+
if (this.opts.column !== 1 && !this.opts.disableOneColumnMode && this._widthOrContainer() <= this.opts.oneColumnSize) {
296302
this._prevColumn = this.getColumn();
297303
this.opts.column = 1;
298304
}
@@ -1388,7 +1394,7 @@ export class GridStack {
13881394
}
13891395
} else {
13901396
// else check for 1 column in/out behavior
1391-
let oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.minWidth;
1397+
let oneColumn = !this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.oneColumnSize;
13921398
if ((this.opts.column === 1) !== oneColumn) {
13931399
changedColumn = true;
13941400
if (this.opts.animate) { this.setAnimation(false); } // 1 <-> 12 is too radical, turn off animation

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export interface GridStackOptions {
8585
/** disallows dragging of widgets (default?: false) */
8686
disableDrag?: boolean;
8787

88-
/** disables the onColumnMode when the grid width is less than minWidth (default?: false) */
88+
/** disables the onColumnMode when the grid width is less than oneColumnSize (default?: false) */
8989
disableOneColumnMode?: boolean;
9090

9191
/** disallows resizing of widgets (default?: false). */
@@ -150,8 +150,8 @@ export interface GridStackOptions {
150150
*/
151151
minRow?: number;
152152

153-
/** minimal width. If grid width is less, grid will be shown in one column mode (default?: 768) */
154-
minWidth?: number;
153+
/** minimal width before grid will be shown in one column mode (default?: 768) */
154+
oneColumnSize?: number;
155155

156156
/**
157157
* set to true if you want oneColumnMode to use the DOM order and ignore x,y from normal multi column

src/utils.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,17 @@ export class Utils {
220220
}
221221

222222
/** copies over b size & position (GridStackPosition), and possibly min/max as well */
223-
static copyPos(a: GridStackWidget, b: GridStackWidget, minMax = false): GridStackWidget {
223+
static copyPos(a: GridStackWidget, b: GridStackWidget, doMinMax = false): GridStackWidget {
224224
a.x = b.x;
225225
a.y = b.y;
226226
a.w = b.w;
227227
a.h = b.h;
228-
if (!minMax) return a;
229-
if (b.minW) a.minW = b.minW;
230-
if (b.minH) a.minH = b.minH;
231-
if (b.maxW) a.maxW = b.maxW;
232-
if (b.maxH) a.maxH = b.maxH;
228+
if (doMinMax) {
229+
if (b.minW) a.minW = b.minW;
230+
if (b.minH) a.minH = b.minH;
231+
if (b.maxW) a.maxW = b.maxW;
232+
if (b.maxH) a.maxH = b.maxH;
233+
}
233234
return a;
234235
}
235236

0 commit comments

Comments
 (0)