Skip to content

fix(grid-list): allow more units for gutter width and row height #14341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib/grid-list/grid-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ describe('MatGridList', () => {
expect(getStyle(tiles[2], 'top')).toBe('102px');
});

it('should allow alternate units for the gutter size', () => {
const fixture = createComponent(GridListWithUnspecifiedGutterSize);
const gridList = fixture.debugElement.query(By.directive(MatGridList));

gridList.componentInstance.gutterSize = '10%';
fixture.detectChanges();

const tiles = fixture.debugElement.queryAll(By.css('mat-grid-tile'));

expect(getStyle(tiles[0], 'width')).toBe('90px');
expect(getComputedLeft(tiles[1])).toBe(110);
});

it('should set the correct list height in ratio mode', () => {
const fixture = createComponent(GridListWithRatioHeightAndMulipleRows);
fixture.detectChanges();
Expand Down
6 changes: 4 additions & 2 deletions src/lib/grid-list/tile-styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ export class FitTileStyler extends TileStyler {


/** Wraps a CSS string in a calc function */
function calc(exp: string): string { return `calc(${exp})`; }
function calc(exp: string): string {
return `calc(${exp})`;
}


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