Skip to content

Commit 06555c3

Browse files
crisbetojosephperrott
authored andcommitted
fix(grid-list): unable to assign numeric zero as gutter size (#13652)
1 parent 0898827 commit 06555c3

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ describe('MatGridList', () => {
4646
}).not.toThrow();
4747
});
4848

49+
it('should preserve value when zero is set as row height', () => {
50+
const fixture = createComponent(GridListWithUnspecifiedRowHeight);
51+
const gridList = fixture.debugElement.query(By.directive(MatGridList)).componentInstance;
52+
53+
gridList.rowHeight = 0;
54+
expect(gridList.rowHeight).toBe('0');
55+
});
56+
4957
it('should set the columns to zero if a negative number is passed in', () => {
5058
const fixture = createComponent(GridListWithDynamicCols);
5159
fixture.detectChanges();
@@ -139,6 +147,24 @@ describe('MatGridList', () => {
139147
expect(getStyle(tiles[2], 'top')).toBe('101px');
140148
});
141149

150+
it('should be able to set the gutter size to zero', () => {
151+
const fixture = createComponent(GridListWithUnspecifiedGutterSize);
152+
const gridList = fixture.debugElement.query(By.directive(MatGridList));
153+
154+
gridList.componentInstance.gutterSize = 0;
155+
fixture.detectChanges();
156+
157+
const tiles = fixture.debugElement.queryAll(By.css('mat-grid-tile'));
158+
159+
// check horizontal gutter
160+
expect(getStyle(tiles[0], 'width')).toBe('100px');
161+
expect(getComputedLeft(tiles[1])).toBe(100);
162+
163+
// check vertical gutter
164+
expect(getStyle(tiles[0], 'height')).toBe('100px');
165+
expect(getStyle(tiles[2], 'top')).toBe('100px');
166+
});
167+
142168
it('should lay out the tiles correctly for a nested grid list', () => {
143169
const fixture = createComponent(NestedGridList);
144170
fixture.detectChanges();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ export class MatGridList implements MatGridListBase, OnInit, AfterContentChecked
8585
/** Size of the grid list's gutter in pixels. */
8686
@Input()
8787
get gutterSize(): string { return this._gutter; }
88-
set gutterSize(value: string) { this._gutter = `${value || ''}`; }
88+
set gutterSize(value: string) { this._gutter = `${value == null ? '' : value}`; }
8989

9090
/** Set internal representation of row height from the user-provided value. */
9191
@Input()
92+
get rowHeight(): string | number { return this._rowHeight; }
9293
set rowHeight(value: string | number) {
93-
const newValue = `${value || ''}`;
94+
const newValue = `${value == null ? '' : value}`;
9495

9596
if (newValue !== this._rowHeight) {
9697
this._rowHeight = newValue;

0 commit comments

Comments
 (0)