Skip to content

Commit f176119

Browse files
crisbetommalerba
authored andcommittedDec 3, 2018
fix(grid-list): allow more units for gutter width and row height (#14341)
Currently the function that normalizes the units only allows `px`, `em` and `rem`. These changes expand it to cover more units.
1 parent 166279b commit f176119

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎src/lib/grid-list/grid-list.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ describe('MatGridList', () => {
207207
expect(getStyle(tiles[2], 'top')).toBe('102px');
208208
});
209209

210+
it('should allow alternate units for the gutter size', () => {
211+
const fixture = createComponent(GridListWithUnspecifiedGutterSize);
212+
const gridList = fixture.debugElement.query(By.directive(MatGridList));
213+
214+
gridList.componentInstance.gutterSize = '10%';
215+
fixture.detectChanges();
216+
217+
const tiles = fixture.debugElement.queryAll(By.css('mat-grid-tile'));
218+
219+
expect(getStyle(tiles[0], 'width')).toBe('90px');
220+
expect(getComputedLeft(tiles[1])).toBe(110);
221+
});
222+
210223
it('should set the correct list height in ratio mode', () => {
211224
const fixture = createComponent(GridListWithRatioHeightAndMulipleRows);
212225
fixture.detectChanges();

‎src/lib/grid-list/tile-styler.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,13 @@ export class FitTileStyler extends TileStyler {
286286

287287

288288
/** Wraps a CSS string in a calc function */
289-
function calc(exp: string): string { return `calc(${exp})`; }
289+
function calc(exp: string): string {
290+
return `calc(${exp})`;
291+
}
290292

291293

292294
/** Appends pixels to a CSS string if no units are given. */
293295
function normalizeUnits(value: string): string {
294-
return (value.match(/px|em|rem/)) ? value : value + 'px';
296+
return value.match(/([A-Za-z%]+)$/) ? value : `${value}px`;
295297
}
296298

0 commit comments

Comments
 (0)
Please sign in to comment.