Skip to content

Commit 2c680d4

Browse files
crisbetommalerba
authored andcommitted
fix(list): not picking up indirect descendant lines
Fixes the `mat-list-item` not picking up `mat-line`, if it's not a direct descendant. Fixes #15466.
1 parent debc56e commit 2c680d4

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/lib/list/list.spec.ts

+28-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@ describe('MatList', () => {
1313
TestBed.configureTestingModule({
1414
imports: [MatListModule],
1515
declarations: [
16-
ListWithOneAnchorItem,
17-
ListWithOneItem,
18-
ListWithTwoLineItem,
19-
ListWithThreeLineItem,
20-
ListWithAvatar,
21-
ListWithItemWithCssClass,
22-
ListWithDynamicNumberOfLines,
23-
ListWithMultipleItems,
24-
ListWithManyLines,
25-
NavListWithOneAnchorItem,
26-
ActionListWithoutType,
27-
ActionListWithType
16+
ListWithOneAnchorItem, ListWithOneItem, ListWithTwoLineItem, ListWithThreeLineItem,
17+
ListWithAvatar, ListWithItemWithCssClass, ListWithDynamicNumberOfLines,
18+
ListWithMultipleItems, ListWithManyLines, NavListWithOneAnchorItem, ActionListWithoutType,
19+
ActionListWithType, ListWithIndirectDescendantLines
2820
],
2921
});
3022

@@ -274,6 +266,15 @@ describe('MatList', () => {
274266
.toBe(0, 'Expected no ripples after list ripples are disabled.');
275267
}));
276268

269+
270+
it('should pick up indirect descendant lines', () => {
271+
const fixture = TestBed.createComponent(ListWithIndirectDescendantLines);
272+
fixture.detectChanges();
273+
274+
const listItems = fixture.debugElement.children[0].queryAll(By.css('mat-list-item'));
275+
expect(listItems[0].nativeElement.className).toContain('mat-2-line');
276+
expect(listItems[1].nativeElement.className).toContain('mat-2-line');
277+
});
277278
});
278279

279280

@@ -409,3 +410,18 @@ class ListWithDynamicNumberOfLines extends BaseTestList { }
409410
</mat-list-item>
410411
</mat-list>`})
411412
class ListWithMultipleItems extends BaseTestList { }
413+
414+
// Note the blank `ngSwitch` which we need in order to hit the bug that we're testing.
415+
@Component({
416+
template: `
417+
<mat-list>
418+
<mat-list-item *ngFor="let item of items">
419+
<ng-container [ngSwitch]="true">
420+
<h3 mat-line>{{item.name}}</h3>
421+
<p mat-line>{{item.description}}</p>
422+
</ng-container>
423+
</mat-list-item>
424+
</mat-list>`
425+
})
426+
class ListWithIndirectDescendantLines extends BaseTestList {
427+
}

src/lib/list/list.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class MatListItem extends _MatListItemMixinBase implements AfterContentIn
180180
private _list?: MatNavList | MatList;
181181
private _destroyed = new Subject<void>();
182182

183-
@ContentChildren(MatLine) _lines: QueryList<MatLine>;
183+
@ContentChildren(MatLine, {descendants: true}) _lines: QueryList<MatLine>;
184184
@ContentChild(MatListAvatarCssMatStyler) _avatar: MatListAvatarCssMatStyler;
185185
@ContentChild(MatListIconCssMatStyler) _icon: MatListIconCssMatStyler;
186186

0 commit comments

Comments
 (0)