File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 99
99
var height = val ;
100
100
var heightUnit = 'px' ;
101
101
if ( height && _ . isString ( height ) ) {
102
- var match = height . match ( / ^ ( [ 0 - 9 ] * \. [ 0 - 9 ] + | [ 0 - 9 ] + ) ( p x | e m | r e m | v h | v w ) ? $ / ) ;
102
+ var match = height . match ( / ^ ( - [ 0 - 9 ] + \. [ 0 - 9 ] + | [ 0 - 9 ] * \. [ 0 - 9 ] + | - [ 0 - 9 ] + | [ 0 - 9 ] + ) ( p x | e m | r e m | v h | v w ) ? $ / ) ;
103
103
if ( ! match ) {
104
104
throw new Error ( 'Invalid height' ) ;
105
105
}
Original file line number Diff line number Diff line change @@ -90,8 +90,18 @@ describe('gridstack utils', function() {
90
90
expect ( utils . parseHeight ( '12.3vh' ) ) . toEqual ( jasmine . objectContaining ( { height : 12.3 , unit : 'vh' } ) ) ;
91
91
expect ( utils . parseHeight ( '12.3vw' ) ) . toEqual ( jasmine . objectContaining ( { height : 12.3 , unit : 'vw' } ) ) ;
92
92
expect ( utils . parseHeight ( '12.5' ) ) . toEqual ( jasmine . objectContaining ( { height : 12.5 , unit : 'px' } ) ) ;
93
- expect ( function ( ) { utils . parseHeight ( '12.5 df' ) ; } ) . toThrowError ( 'Invalid height' ) ;
94
93
} ) ;
95
94
95
+ it ( 'should parse negative height value' , function ( ) {
96
+ expect ( utils . parseHeight ( - 12 ) ) . toEqual ( jasmine . objectContaining ( { height : - 12 , unit : 'px' } ) ) ;
97
+ expect ( utils . parseHeight ( '-12px' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12 , unit : 'px' } ) ) ;
98
+ expect ( utils . parseHeight ( '-12.3px' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'px' } ) ) ;
99
+ expect ( utils . parseHeight ( '-12.3em' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'em' } ) ) ;
100
+ expect ( utils . parseHeight ( '-12.3rem' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'rem' } ) ) ;
101
+ expect ( utils . parseHeight ( '-12.3vh' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'vh' } ) ) ;
102
+ expect ( utils . parseHeight ( '-12.3vw' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.3 , unit : 'vw' } ) ) ;
103
+ expect ( utils . parseHeight ( '-12.5' ) ) . toEqual ( jasmine . objectContaining ( { height : - 12.5 , unit : 'px' } ) ) ;
104
+ expect ( function ( ) { utils . parseHeight ( '-12.5 df' ) ; } ) . toThrowError ( 'Invalid height' ) ;
105
+ } ) ;
96
106
} ) ;
97
107
} ) ;
You can’t perform that action at this time.
0 commit comments