From 755201c2d2ee5e1f75374d6208406f63c95c6d96 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 3 Feb 2017 11:57:06 +0100 Subject: [PATCH] fix(toolbar): add toolbar role to host element * Add the toolbar `role` attribute to the host element to have proper accessibility support. Fixes #2909 --- src/lib/toolbar/toolbar.spec.ts | 21 ++++++++++++++++----- src/lib/toolbar/toolbar.ts | 3 +++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lib/toolbar/toolbar.spec.ts b/src/lib/toolbar/toolbar.spec.ts index d0f6067f84f0..18354d761162 100644 --- a/src/lib/toolbar/toolbar.spec.ts +++ b/src/lib/toolbar/toolbar.spec.ts @@ -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; + 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'); + }); + }); diff --git a/src/lib/toolbar/toolbar.ts b/src/lib/toolbar/toolbar.ts index 691c274a3fea..831b3914958e 100644 --- a/src/lib/toolbar/toolbar.ts +++ b/src/lib/toolbar/toolbar.ts @@ -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 })