Skip to content
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

fix(grid-list): default to LTR when Directionality value is empty #10111

Merged
merged 1 commit into from
Feb 24, 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
33 changes: 32 additions & 1 deletion src/lib/grid-list/grid-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Component, DebugElement} from '@angular/core';
import {By} from '@angular/platform-browser';
import {MatGridList, MatGridListModule} from './index';
import {MatGridTile, MatGridTileText} from './grid-tile';
import {Directionality} from '@angular/cdk/bidi';


describe('MatGridList', () => {
Expand All @@ -29,6 +30,8 @@ describe('MatGridList', () => {
GridListWithFootersWithoutLines,
GridListWithFooterContainingTwoLines,
GridListWithoutMatchingGap,
GridListWithEmptyDirectionality,
GridListWithRtl,
],
});

Expand Down Expand Up @@ -297,6 +300,23 @@ describe('MatGridList', () => {
.toBe(true, 'Expected none of the tiles to have a negative `left`');
});

it('should default to LTR if empty directionality is given', () => {
const fixture = TestBed.createComponent(GridListWithEmptyDirectionality);
const tile: HTMLElement = fixture.debugElement.query(By.css('mat-grid-tile')).nativeElement;
fixture.detectChanges();

expect(tile.style.left).toBe('0px');
expect(tile.style.right).toBe('');
});

it('should set `right` styles for RTL', () => {
const fixture = TestBed.createComponent(GridListWithRtl);
const tile: HTMLElement = fixture.debugElement.query(By.css('mat-grid-tile')).nativeElement;
fixture.detectChanges();

expect(tile.style.left).toBe('');
expect(tile.style.right).toBe('0px');
});
});


Expand All @@ -317,7 +337,6 @@ function getComputedLeft(element: DebugElement): number {
}



@Component({template: '<mat-grid-list></mat-grid-list>'})
class GridListWithoutCols { }

Expand Down Expand Up @@ -478,3 +497,15 @@ class GridListWithFooterContainingTwoLines { }
</mat-grid-list>
`})
class GridListWithoutMatchingGap { }

@Component({
template: `<mat-grid-list cols="1"><mat-grid-tile>Hello</mat-grid-tile></mat-grid-list>`,
providers: [{provide: Directionality, useValue: {}}]
})
class GridListWithEmptyDirectionality { }

@Component({
template: `<mat-grid-list cols="1"><mat-grid-tile>Hello</mat-grid-tile></mat-grid-list>`,
providers: [{provide: Directionality, useValue: {value: 'rtl'}}]
})
class GridListWithRtl { }
2 changes: 1 addition & 1 deletion src/lib/grid-list/tile-styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export abstract class TileStyler {

// The width and horizontal position of each tile is always calculated the same way, but the
// height and vertical position depends on the rowMode.
let side = this._direction === 'ltr' ? 'left' : 'right';
let side = this._direction === 'rtl' ? 'right' : 'left';
tile._setStyle(side, this.getTilePosition(baseTileWidth, colIndex));
tile._setStyle('width', calc(this.getTileSize(baseTileWidth, tile.colspan)));
}
Expand Down