Skip to content

Commit

Permalink
fix(toolbar): not picking up indirect descendant rows (#17469)
Browse files Browse the repository at this point in the history
Fixes `mat-toolbar` not picking up rows that aren't direct descendants.
  • Loading branch information
crisbeto authored and mmalerba committed Oct 24, 2019
1 parent 16d2eb8 commit 646d47f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/material/toolbar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ng_test_library(
),
deps = [
":toolbar",
"@npm//@angular/common",
"@npm//@angular/platform-browser",
],
)
Expand Down
33 changes: 31 additions & 2 deletions src/material/toolbar/toolbar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import {Component} from '@angular/core';
import {TestBed, async, ComponentFixture, fakeAsync, flush} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {CommonModule} from '@angular/common';
import {MatToolbarModule} from './index';

describe('MatToolbar', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatToolbarModule],
declarations: [ToolbarSingleRow, ToolbarMultipleRows, ToolbarMixedRowModes],
imports: [MatToolbarModule, CommonModule],
declarations: [
ToolbarSingleRow,
ToolbarMultipleRows,
ToolbarMixedRowModes,
ToolbarMultipleIndirectRows,
],
});

TestBed.compileComponents();
Expand Down Expand Up @@ -84,6 +90,15 @@ describe('MatToolbar', () => {
}
}).toThrowError(/attempting to combine different/i);
}));

it('should pick up indirect descendant rows', () => {
const fixture = TestBed.createComponent(ToolbarMultipleIndirectRows);
fixture.detectChanges();
const toolbar = fixture.nativeElement.querySelector('.mat-toolbar');

expect(toolbar.classList).toContain('mat-toolbar-multiple-rows');
});

});

});
Expand Down Expand Up @@ -121,3 +136,17 @@ class ToolbarMultipleRows {}
class ToolbarMixedRowModes {
showToolbarRow: boolean = true;
}


@Component({
// The ng-container is there so we have a node with a directive between the toolbar and the rows.
template: `
<mat-toolbar>
<ng-container [ngSwitch]="true">
<mat-toolbar-row>First Row</mat-toolbar-row>
<mat-toolbar-row>Second Row</mat-toolbar-row>
</ng-container>
</mat-toolbar>
`
})
class ToolbarMultipleIndirectRows {}
2 changes: 1 addition & 1 deletion src/material/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class MatToolbar extends _MatToolbarMixinBase implements CanColor, AfterV
private _document: Document;

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

constructor(
elementRef: ElementRef,
Expand Down

0 comments on commit 646d47f

Please sign in to comment.