Skip to content

Commit ee863b2

Browse files
crisbetommalerba
authored andcommitted
fix(list): selection list option not picking up indirect desce… (#17514)
Fixes `mat-list-option` not picking up `mat-line` instances that aren't direct descendants.
1 parent 7f1c2ca commit ee863b2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/material/list/selection-list.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('MatSelectionList without forms', () => {
4040
SelectionListWithOnlyOneOption,
4141
SelectionListWithIndirectChildOptions,
4242
SelectionListWithSelectedOptionAndValue,
43+
SelectionListWithIndirectDescendantLines,
4344
],
4445
});
4546

@@ -603,6 +604,14 @@ describe('MatSelectionList without forms', () => {
603604
expect(listItemEl.componentInstance.value).toBe(componentFixture.componentInstance.itemValue);
604605
});
605606

607+
it('should pick up indirect descendant lines', () => {
608+
const componentFixture = TestBed.createComponent(SelectionListWithIndirectDescendantLines);
609+
componentFixture.detectChanges();
610+
611+
const option = componentFixture.nativeElement.querySelector('mat-list-option');
612+
expect(option.classList).toContain('mat-2-line');
613+
});
614+
606615
});
607616

608617
describe('with list option selected', () => {
@@ -1445,3 +1454,18 @@ class SelectionListWithIcon {
14451454
class SelectionListWithIndirectChildOptions {
14461455
@ViewChildren(MatListOption) optionInstances: QueryList<MatListOption>;
14471456
}
1457+
1458+
// Note the blank `ngSwitch` which we need in order to hit the bug that we're testing.
1459+
@Component({
1460+
template: `
1461+
<mat-selection-list>
1462+
<mat-list-option>
1463+
<ng-container [ngSwitch]="true">
1464+
<h3 mat-line>Item</h3>
1465+
<p mat-line>Item description</p>
1466+
</ng-container>
1467+
</mat-list-option>
1468+
</mat-selection-list>`
1469+
})
1470+
class SelectionListWithIndirectDescendantLines {
1471+
}

src/material/list/selection-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class MatListOption extends _MatListOptionMixinBase implements AfterConte
125125

126126
@ContentChild(MatListAvatarCssMatStyler) _avatar: MatListAvatarCssMatStyler;
127127
@ContentChild(MatListIconCssMatStyler) _icon: MatListIconCssMatStyler;
128-
@ContentChildren(MatLine) _lines: QueryList<MatLine>;
128+
@ContentChildren(MatLine, {descendants: true}) _lines: QueryList<MatLine>;
129129

130130
/** DOM element containing the item's text. */
131131
@ViewChild('text') _text: ElementRef;

0 commit comments

Comments
 (0)