Skip to content

Commit c12d7c4

Browse files
crisbetojelbourn
authored andcommitted
fix(checkbox): setting blank aria-label by default (#10281)
Fixes the checkbox adding a blank `aria-label` to the underlying input element by default.
1 parent 26ee3e7 commit c12d7c4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/lib/checkbox/checkbox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[attr.name]="name"
1212
[tabIndex]="tabIndex"
1313
[indeterminate]="indeterminate"
14-
[attr.aria-label]="ariaLabel"
14+
[attr.aria-label]="ariaLabel || null"
1515
[attr.aria-labelledby]="ariaLabelledby"
1616
[attr.aria-checked]="_getAriaChecked()"
1717
(change)="_onInteractionEvent($event)"

src/lib/checkbox/checkbox.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ describe('MatCheckbox', () => {
701701
}));
702702
});
703703

704-
describe('with provided aria-label ', () => {
704+
describe('aria-label ', () => {
705705
let checkboxDebugElement: DebugElement;
706706
let checkboxNativeElement: HTMLElement;
707707
let inputElement: HTMLInputElement;
@@ -715,6 +715,13 @@ describe('MatCheckbox', () => {
715715
fixture.detectChanges();
716716
expect(inputElement.getAttribute('aria-label')).toBe('Super effective');
717717
});
718+
719+
it('should not set the aria-label attribute if no value is provided', () => {
720+
fixture = TestBed.createComponent(SingleCheckbox);
721+
fixture.detectChanges();
722+
723+
expect(fixture.nativeElement.querySelector('input').hasAttribute('aria-label')).toBe(false);
724+
});
718725
});
719726

720727
describe('with provided aria-labelledby ', () => {

0 commit comments

Comments
 (0)