Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toolbar): not picking up indirect descendant rows #17469

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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