Skip to content

Commit 8989dfa

Browse files
author
Alain Dumesny
authored
Merge pull request #1093 from adumesny/develop
Allow percentage as a valid unit for height
2 parents 3b8f016 + c727a09 commit 8989dfa

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

doc/CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Change log
2727

2828
## v0.5.5-dev (upcoming changes)
2929

30-
- add `float(val)` to set/get the grid float mode
30+
- add `float(val)` to set/get the grid float mode [#1088](https://github.com/gridstack/gridstack.js/pull/1088)
31+
- Allow percentage as a valid unit for height [#1093](https://github.com/gridstack/gridstack.js/pull/1093)
3132

3233
## v0.5.5 (2019-11-27)
3334

doc/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ gridstack.js API
6969
- `auto` - if `false` gridstack will not initialize existing items (default: `true`)
7070
- `cellHeight` - one cell height (default: `60`). Can be:
7171
* an integer (px)
72-
* a string (ex: '10em', '100px', '10rem')
72+
* a string (ex: '100px', '10em', '10rem', '10%')
7373
* 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
74-
* `'auto'` - height will be calculated from cell width.
74+
* `'auto'` - height will be calculated to match cell width (initial square grid).
7575
- `column` - amount of columns (default: `12`)
7676
- `ddPlugin` - class that implement drag'n'drop functionallity for gridstack. If `false` grid will be static. (default: `null` - first available plugin will be used)
7777
- `disableDrag` - disallows dragging of widgets (default: `false`).

spec/utils-spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ describe('gridstack utils', function() {
8989
expect(utils.parseHeight('12.3rem')).toEqual(jasmine.objectContaining({height: 12.3, unit: 'rem'}));
9090
expect(utils.parseHeight('12.3vh')).toEqual(jasmine.objectContaining({height: 12.3, unit: 'vh'}));
9191
expect(utils.parseHeight('12.3vw')).toEqual(jasmine.objectContaining({height: 12.3, unit: 'vw'}));
92+
expect(utils.parseHeight('12.3%')).toEqual(jasmine.objectContaining({height: 12.3, unit: '%'}));
9293
expect(utils.parseHeight('12.5')).toEqual(jasmine.objectContaining({height: 12.5, unit: 'px'}));
9394
expect(function() { utils.parseHeight('12.5 df'); }).toThrowError('Invalid height');
9495

@@ -102,6 +103,7 @@ describe('gridstack utils', function() {
102103
expect(utils.parseHeight('-12.3rem')).toEqual(jasmine.objectContaining({height: -12.3, unit: 'rem'}));
103104
expect(utils.parseHeight('-12.3vh')).toEqual(jasmine.objectContaining({height: -12.3, unit: 'vh'}));
104105
expect(utils.parseHeight('-12.3vw')).toEqual(jasmine.objectContaining({height: -12.3, unit: 'vw'}));
106+
expect(utils.parseHeight('-12.3%')).toEqual(jasmine.objectContaining({height: -12.3, unit: '%'}));
105107
expect(utils.parseHeight('-12.5')).toEqual(jasmine.objectContaining({height: -12.5, unit: 'px'}));
106108
expect(function() { utils.parseHeight('-12.5 df'); }).toThrowError('Invalid height');
107109
});

src/gridstack.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ interface GridstackOptions {
415415
/**
416416
* one cell height (default?: 60). Can be:
417417
* an integer (px)
418-
* a string (ex: '10em', '100px', '10rem')
418+
* a string (ex: '100px', '10em', '10rem', '10%')
419419
* 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
420-
* 'auto' - height will be calculated from cell width.
420+
* 'auto' - height will be calculated to match cell width (initial square grid).
421421
*/
422422
cellHeight ? : number | string;
423423

src/gridstack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
var height = val;
119119
var heightUnit = 'px';
120120
if (height && typeof height === 'string') {
121-
var match = height.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw)?$/);
121+
var match = height.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw|%)?$/);
122122
if (!match) {
123123
throw new Error('Invalid height');
124124
}

0 commit comments

Comments
 (0)