Skip to content

Commit 31bf7ef

Browse files
committed
fix(grid-list): make dir optional
1 parent 7a9df1e commit 31bf7ef

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/components/grid-list/grid-list.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
ContentChildren,
88
QueryList,
99
Renderer,
10-
ElementRef
10+
ElementRef,
11+
Optional
1112
} from '@angular/core';
1213
import {MdGridTile} from './grid-tile';
1314
import {TileCoordinator} from './tile-coordinator';
@@ -57,7 +58,7 @@ export class MdGridList implements OnInit, AfterContentChecked {
5758
constructor(
5859
private _renderer: Renderer,
5960
private _element: ElementRef,
60-
private _dir: Dir) {}
61+
@Optional() private _dir: Dir) {}
6162

6263
@Input()
6364
get cols() {
@@ -128,7 +129,8 @@ export class MdGridList implements OnInit, AfterContentChecked {
128129
private _layoutTiles(): void {
129130
let tiles = this._tiles.toArray();
130131
let tracker = new TileCoordinator(this.cols, tiles);
131-
this._tileStyler.init(this.gutterSize, tracker, this.cols, this._dir);
132+
let direction = this._dir ? this._dir.value : 'ltr';
133+
this._tileStyler.init(this.gutterSize, tracker, this.cols, direction);
132134

133135
for (let i = 0; i < tiles.length; i++) {
134136
let pos = tracker.positions[i];

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {MdGridTile} from './grid-tile';
22
import {TileCoordinator} from './tile-coordinator';
33
import {MdGridListBadRatioError} from './grid-list-errors';
4-
import {Dir} from '@angular2-material/core/rtl/dir';
54

65
/* Sets the style properties for an individual tile, given the position calculated by the
76
* Tile Coordinator. */
@@ -10,18 +9,18 @@ export class TileStyler {
109
_rows: number = 0;
1110
_rowspan: number = 0;
1211
_cols: number;
13-
_dir: Dir;
12+
_direction: string;
1413

1514
/** Adds grid-list layout info once it is available. Cannot be processed in the constructor
1615
* because these properties haven't been calculated by that point.
1716
* @internal
1817
* */
19-
init(_gutterSize: string, tracker: TileCoordinator, cols: number, dir: Dir): void {
18+
init(_gutterSize: string, tracker: TileCoordinator, cols: number, direction: string): void {
2019
this._gutterSize = normalizeUnits(_gutterSize);
2120
this._rows = tracker.rowCount;
2221
this._rowspan = tracker.rowspan;
2322
this._cols = cols;
24-
this._dir = dir;
23+
this._direction = direction;
2524
}
2625

2726
/**
@@ -93,7 +92,7 @@ export class TileStyler {
9392

9493
// The width and horizontal position of each tile is always calculated the same way, but the
9594
// height and vertical position depends on the rowMode.
96-
let side = this._dir.value === 'ltr' ? 'left' : 'right';
95+
let side = this._direction === 'ltr' ? 'left' : 'right';
9796
tile.setStyle(side, this.getTilePosition(baseTileWidth, colIndex));
9897
tile.setStyle('width', calc(this.getTileSize(baseTileWidth, tile.colspan)));
9998
}
@@ -119,8 +118,8 @@ export class FixedTileStyler extends TileStyler {
119118
constructor(public fixedRowHeight: string) { super(); }
120119

121120
/** @internal */
122-
init(gutterSize: string, tracker: TileCoordinator, cols: number, dir: Dir) {
123-
super.init(gutterSize, tracker, cols, dir);
121+
init(gutterSize: string, tracker: TileCoordinator, cols: number, direction: string) {
122+
super.init(gutterSize, tracker, cols, direction);
124123
this.fixedRowHeight = normalizeUnits(this.fixedRowHeight);
125124
}
126125

0 commit comments

Comments
 (0)