From 947d3e84d1c032a4f11a5c83a36e34b6bd5f45b1 Mon Sep 17 00:00:00 2001 From: Marcelo Luz Date: Fri, 29 Sep 2017 16:15:02 -0400 Subject: [PATCH] fix(select) aria-labelledby (#7022) aria-labelledby must not be in the DOM if it is empty this causes accessability bugs. --- src/lib/select/select.spec.ts | 9 +++++++++ src/lib/select/select.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index 8a8bb96260d..93fafbcc1d1 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -1802,6 +1802,15 @@ describe('MatSelect', () => { expect(select.getAttribute('aria-labelledby')).toBe('myLabelId'); }); + it('should not have aria-labelledby in the DOM if it`s not specified', async(() => { + + fixture.detectChanges(); + + fixture.whenStable().then(() => { + expect(select.hasAttribute('aria-labelledby')).toBeFalsy(); + }); + })); + it('should set the tabindex of the select to 0 by default', () => { expect(select.getAttribute('tabindex')).toEqual('0'); }); diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index 8a5f3d46259..1a5038a9b5f 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -371,7 +371,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit, @Input('aria-label') ariaLabel: string = ''; /** Input that can be used to specify the `aria-labelledby` attribute. */ - @Input('aria-labelledby') ariaLabelledby: string = ''; + @Input('aria-labelledby') ariaLabelledby: string; /** Unique id of the element. */ @Input()