Skip to content

Commit 64ef3a8

Browse files
authored
fix(grid-list): default to LTR when Directionality value is empty (#10111)
1 parent 609a7c8 commit 64ef3a8

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Component, DebugElement} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {MatGridList, MatGridListModule} from './index';
55
import {MatGridTile, MatGridTileText} from './grid-tile';
6+
import {Directionality} from '@angular/cdk/bidi';
67

78

89
describe('MatGridList', () => {
@@ -29,6 +30,8 @@ describe('MatGridList', () => {
2930
GridListWithFootersWithoutLines,
3031
GridListWithFooterContainingTwoLines,
3132
GridListWithoutMatchingGap,
33+
GridListWithEmptyDirectionality,
34+
GridListWithRtl,
3235
],
3336
});
3437

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

303+
it('should default to LTR if empty directionality is given', () => {
304+
const fixture = TestBed.createComponent(GridListWithEmptyDirectionality);
305+
const tile: HTMLElement = fixture.debugElement.query(By.css('mat-grid-tile')).nativeElement;
306+
fixture.detectChanges();
307+
308+
expect(tile.style.left).toBe('0px');
309+
expect(tile.style.right).toBe('');
310+
});
311+
312+
it('should set `right` styles for RTL', () => {
313+
const fixture = TestBed.createComponent(GridListWithRtl);
314+
const tile: HTMLElement = fixture.debugElement.query(By.css('mat-grid-tile')).nativeElement;
315+
fixture.detectChanges();
316+
317+
expect(tile.style.left).toBe('');
318+
expect(tile.style.right).toBe('0px');
319+
});
300320
});
301321

302322

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

319339

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

@@ -478,3 +497,15 @@ class GridListWithFooterContainingTwoLines { }
478497
</mat-grid-list>
479498
`})
480499
class GridListWithoutMatchingGap { }
500+
501+
@Component({
502+
template: `<mat-grid-list cols="1"><mat-grid-tile>Hello</mat-grid-tile></mat-grid-list>`,
503+
providers: [{provide: Directionality, useValue: {}}]
504+
})
505+
class GridListWithEmptyDirectionality { }
506+
507+
@Component({
508+
template: `<mat-grid-list cols="1"><mat-grid-tile>Hello</mat-grid-tile></mat-grid-list>`,
509+
providers: [{provide: Directionality, useValue: {value: 'rtl'}}]
510+
})
511+
class GridListWithRtl { }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export abstract class TileStyler {
106106

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

0 commit comments

Comments
 (0)