diff --git a/src/lib/checkbox/checkbox.html b/src/lib/checkbox/checkbox.html index 9d108b2533e7..c29c859785a1 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 53f2457e2023..141aacf3f659 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 ', () => {