From c12d7c473ef49061500c64b7f1715d488214c523 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Fri, 9 Mar 2018 10:36:09 -0500 Subject: [PATCH] fix(checkbox): setting blank aria-label by default (#10281) Fixes the checkbox adding a blank `aria-label` to the underlying input element by default. --- src/lib/checkbox/checkbox.html | 2 +- src/lib/checkbox/checkbox.spec.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/checkbox/checkbox.html b/src/lib/checkbox/checkbox.html index 9d108b2533e..c29c859785a 100644 --- a/src/lib/checkbox/checkbox.html +++ b/src/lib/checkbox/checkbox.html @@ -11,7 +11,7 @@ [attr.name]="name" [tabIndex]="tabIndex" [indeterminate]="indeterminate" - [attr.aria-label]="ariaLabel" + [attr.aria-label]="ariaLabel || null" [attr.aria-labelledby]="ariaLabelledby" [attr.aria-checked]="_getAriaChecked()" (change)="_onInteractionEvent($event)" diff --git a/src/lib/checkbox/checkbox.spec.ts b/src/lib/checkbox/checkbox.spec.ts index 53f2457e202..141aacf3f65 100644 --- a/src/lib/checkbox/checkbox.spec.ts +++ b/src/lib/checkbox/checkbox.spec.ts @@ -701,7 +701,7 @@ describe('MatCheckbox', () => { })); }); - describe('with provided aria-label ', () => { + describe('aria-label ', () => { let checkboxDebugElement: DebugElement; let checkboxNativeElement: HTMLElement; let inputElement: HTMLInputElement; @@ -715,6 +715,13 @@ describe('MatCheckbox', () => { fixture.detectChanges(); expect(inputElement.getAttribute('aria-label')).toBe('Super effective'); }); + + it('should not set the aria-label attribute if no value is provided', () => { + fixture = TestBed.createComponent(SingleCheckbox); + fixture.detectChanges(); + + expect(fixture.nativeElement.querySelector('input').hasAttribute('aria-label')).toBe(false); + }); }); describe('with provided aria-labelledby ', () => {