Skip to content

Commit 646d47f

Browse files
crisbetommalerba
authored andcommitted
fix(toolbar): not picking up indirect descendant rows (#17469)
Fixes `mat-toolbar` not picking up rows that aren't direct descendants.
1 parent 16d2eb8 commit 646d47f

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/material/toolbar/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ ng_test_library(
5151
),
5252
deps = [
5353
":toolbar",
54+
"@npm//@angular/common",
5455
"@npm//@angular/platform-browser",
5556
],
5657
)

src/material/toolbar/toolbar.spec.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import {Component} from '@angular/core';
22
import {TestBed, async, ComponentFixture, fakeAsync, flush} from '@angular/core/testing';
33
import {By} from '@angular/platform-browser';
4+
import {CommonModule} from '@angular/common';
45
import {MatToolbarModule} from './index';
56

67
describe('MatToolbar', () => {
78

89
beforeEach(async(() => {
910
TestBed.configureTestingModule({
10-
imports: [MatToolbarModule],
11-
declarations: [ToolbarSingleRow, ToolbarMultipleRows, ToolbarMixedRowModes],
11+
imports: [MatToolbarModule, CommonModule],
12+
declarations: [
13+
ToolbarSingleRow,
14+
ToolbarMultipleRows,
15+
ToolbarMixedRowModes,
16+
ToolbarMultipleIndirectRows,
17+
],
1218
});
1319

1420
TestBed.compileComponents();
@@ -84,6 +90,15 @@ describe('MatToolbar', () => {
8490
}
8591
}).toThrowError(/attempting to combine different/i);
8692
}));
93+
94+
it('should pick up indirect descendant rows', () => {
95+
const fixture = TestBed.createComponent(ToolbarMultipleIndirectRows);
96+
fixture.detectChanges();
97+
const toolbar = fixture.nativeElement.querySelector('.mat-toolbar');
98+
99+
expect(toolbar.classList).toContain('mat-toolbar-multiple-rows');
100+
});
101+
87102
});
88103

89104
});
@@ -121,3 +136,17 @@ class ToolbarMultipleRows {}
121136
class ToolbarMixedRowModes {
122137
showToolbarRow: boolean = true;
123138
}
139+
140+
141+
@Component({
142+
// The ng-container is there so we have a node with a directive between the toolbar and the rows.
143+
template: `
144+
<mat-toolbar>
145+
<ng-container [ngSwitch]="true">
146+
<mat-toolbar-row>First Row</mat-toolbar-row>
147+
<mat-toolbar-row>Second Row</mat-toolbar-row>
148+
</ng-container>
149+
</mat-toolbar>
150+
`
151+
})
152+
class ToolbarMultipleIndirectRows {}

src/material/toolbar/toolbar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class MatToolbar extends _MatToolbarMixinBase implements CanColor, AfterV
5656
private _document: Document;
5757

5858
/** Reference to all toolbar row elements that have been projected. */
59-
@ContentChildren(MatToolbarRow) _toolbarRows: QueryList<MatToolbarRow>;
59+
@ContentChildren(MatToolbarRow, {descendants: true}) _toolbarRows: QueryList<MatToolbarRow>;
6060

6161
constructor(
6262
elementRef: ElementRef,

0 commit comments

Comments
 (0)