Skip to content

Commit c04d2ae

Browse files
crisbetojelbourn
authored andcommitted
fix(grid-list): not picking up indirect descendants (#12823)
Fixes tiles that aren't direct descendants of the grid list not being styled. Fixes #12809.
1 parent e6347ff commit c04d2ae

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('MatGridList', () => {
3232
GridListWithoutMatchingGap,
3333
GridListWithEmptyDirectionality,
3434
GridListWithRtl,
35+
GridListWithIndirectTileDescendants,
3536
],
3637
});
3738

@@ -317,6 +318,15 @@ describe('MatGridList', () => {
317318
expect(tile.style.left).toBe('');
318319
expect(tile.style.right).toBe('0px');
319320
});
321+
322+
it('should lay out the tiles if they are not direct descendants of the list', () => {
323+
const fixture = TestBed.createComponent(GridListWithIndirectTileDescendants);
324+
fixture.detectChanges();
325+
326+
const tile = fixture.debugElement.query(By.directive(MatGridTile));
327+
expect(getStyle(tile, 'padding-top')).toBe('200px');
328+
});
329+
320330
});
321331

322332

@@ -509,3 +519,17 @@ class GridListWithEmptyDirectionality { }
509519
providers: [{provide: Directionality, useValue: {value: 'rtl'}}]
510520
})
511521
class GridListWithRtl { }
522+
523+
@Component({
524+
// Note the blank `ngSwitch` which we need in order to hit the bug that we're testing.
525+
template: `
526+
<div style="width:200px">
527+
<mat-grid-list cols="1">
528+
<ng-container [ngSwitch]="true">
529+
<mat-grid-tile></mat-grid-tile>
530+
</ng-container>
531+
</mat-grid-list>
532+
</div>
533+
`
534+
})
535+
class GridListWithIndirectTileDescendants {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class MatGridList implements OnInit, AfterContentChecked {
6262
private _tileStyler: TileStyler;
6363

6464
/** Query list of tiles that are being rendered. */
65-
@ContentChildren(MatGridTile) _tiles: QueryList<MatGridTile>;
65+
@ContentChildren(MatGridTile, {descendants: true}) _tiles: QueryList<MatGridTile>;
6666

6767
constructor(private _element: ElementRef, @Optional() private _dir: Directionality) {}
6868

0 commit comments

Comments
 (0)