fix(toolbar): add toolbar role to host element (#2914)

* Add the toolbar `role` attribute to the host element to have proper accessibility support.

Fixes #2909
This commit is contained in:
Paul Gschwendtner
2017-02-06 23:59:14 +01:00
committed by tinayuangao
parent 46edc235d7
commit 67032ca917
2 changed files with 19 additions and 5 deletions
+16 -5
View File
@@ -1,11 +1,15 @@
import {Component} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
import {TestBed, async, ComponentFixture} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {MdToolbarModule} from './toolbar';
describe('MdToolbar', () => {
let fixture: ComponentFixture<TestApp>;
let testComponent: TestApp;
let toolbarElement: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MdToolbarModule.forRoot()],
@@ -15,11 +19,13 @@ describe('MdToolbar', () => {
TestBed.compileComponents();
}));
it('should apply class based on color attribute', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let toolbarElement = fixture.debugElement.query(By.css('md-toolbar')).nativeElement;
beforeEach(() => {
fixture = TestBed.createComponent(TestApp);
testComponent = fixture.debugElement.componentInstance;
toolbarElement = fixture.debugElement.query(By.css('md-toolbar')).nativeElement;
});
it('should apply class based on color attribute', () => {
testComponent.toolbarColor = 'primary';
fixture.detectChanges();
@@ -37,6 +43,11 @@ describe('MdToolbar', () => {
expect(toolbarElement.classList.contains('md-accent')).toBe(false);
expect(toolbarElement.classList.contains('md-warn')).toBe(true);
});
it('should set the toolbar role on the host', () => {
expect(toolbarElement.getAttribute('role')).toBe('toolbar');
});
});
+3
View File
@@ -22,6 +22,9 @@ export class MdToolbarRow {}
selector: 'md-toolbar, mat-toolbar',
templateUrl: 'toolbar.html',
styleUrls: ['toolbar.css'],
host: {
role: 'toolbar'
},
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
})