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(icon): add caching of md-icon aria-label #2649

Merged
merged 1 commit into from
Jan 31, 2017
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
15 changes: 15 additions & 0 deletions src/lib/icon/icon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,21 @@ describe('MdIcon', () => {
expect(mdIconElement.getAttribute('aria-label')).toBe('hand');
});

it('should not set aria label unless it actually changed', () => {
let fixture = TestBed.createComponent(MdIconLigatureTestApp);

const testComponent = fixture.componentInstance;
const mdIconElement = fixture.debugElement.nativeElement.querySelector('md-icon');
testComponent.iconName = 'home';

fixture.detectChanges();
expect(mdIconElement.getAttribute('aria-label')).toBe('home');

mdIconElement.removeAttribute('aria-label');
fixture.detectChanges();
expect(mdIconElement.getAttribute('aria-label')).toBeFalsy();
});

it('should use alt tag if aria label is not specified', () => {
let fixture = TestBed.createComponent(MdIconLigatureWithAriaBindingTestApp);

Expand Down
4 changes: 3 additions & 1 deletion src/lib/icon/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class MdIcon implements OnChanges, OnInit, AfterViewChecked {

private _previousFontSetClass: string;
private _previousFontIconClass: string;
private _previousAriaLabel: string;

constructor(
private _elementRef: ElementRef,
Expand Down Expand Up @@ -176,7 +177,8 @@ export class MdIcon implements OnChanges, OnInit, AfterViewChecked {

private _updateAriaLabel() {
const ariaLabel = this._getAriaLabel();
if (ariaLabel) {
if (ariaLabel && ariaLabel !== this._previousAriaLabel) {
this._previousAriaLabel = ariaLabel;
this._renderer.setElementAttribute(this._elementRef.nativeElement, 'aria-label', ariaLabel);
}
}
Expand Down