Skip to content

Commit

Permalink
fix(toolbar): add toolbar role to host element (#2914)
Browse files Browse the repository at this point in the history
* Add the toolbar `role` attribute to the host element to have proper accessibility support.

Fixes #2909
  • Loading branch information
devversion authored and tinayuangao committed Feb 6, 2017
1 parent 46edc23 commit 67032ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/lib/toolbar/toolbar.spec.ts
Original file line number Diff line number Diff line change
@@ -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()],
Expand All @@ -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();

Expand All @@ -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');
});

});


Expand Down
3 changes: 3 additions & 0 deletions src/lib/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down

0 comments on commit 67032ca

Please sign in to comment.