Skip to content

Commit 95dba59

Browse files
crisbetojelbourn
authored andcommitted
fix(button-toggle): setting blank aria-label attribute by default (#10605)
Fixes the button toggle setting the `aria-label` of its underlying input to a blank value by default.
1 parent b38b966 commit 95dba59

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/lib/button-toggle/button-toggle.spec.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -622,16 +622,22 @@ describe('MatButtonToggle without forms', () => {
622622

623623
});
624624

625-
describe('with provided aria-label ', () => {
626-
let checkboxDebugElement: DebugElement;
627-
let checkboxNativeElement: HTMLElement;
628-
let inputElement: HTMLInputElement;
625+
describe('aria-label handling ', () => {
626+
it('should not set the aria-label attribute if none is provided', () => {
627+
let fixture = TestBed.createComponent(StandaloneButtonToggle);
628+
let checkboxDebugElement = fixture.debugElement.query(By.directive(MatButtonToggle));
629+
let checkboxNativeElement = checkboxDebugElement.nativeElement;
630+
let inputElement = checkboxNativeElement.querySelector('input') as HTMLInputElement;
631+
632+
fixture.detectChanges();
633+
expect(inputElement.hasAttribute('aria-label')).toBe(false);
634+
});
629635

630636
it('should use the provided aria-label', () => {
631637
let fixture = TestBed.createComponent(ButtonToggleWithAriaLabel);
632-
checkboxDebugElement = fixture.debugElement.query(By.directive(MatButtonToggle));
633-
checkboxNativeElement = checkboxDebugElement.nativeElement;
634-
inputElement = checkboxNativeElement.querySelector('input') as HTMLInputElement;
638+
let checkboxDebugElement = fixture.debugElement.query(By.directive(MatButtonToggle));
639+
let checkboxNativeElement = checkboxDebugElement.nativeElement;
640+
let inputElement = checkboxNativeElement.querySelector('input') as HTMLInputElement;
635641

636642
fixture.detectChanges();
637643
expect(inputElement.getAttribute('aria-label')).toBe('Super effective');

src/lib/button-toggle/button-toggle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
340340
* Attached to the aria-label attribute of the host element. In most cases, arial-labelledby will
341341
* take precedence so this may be omitted.
342342
*/
343-
@Input('aria-label') ariaLabel: string = '';
343+
@Input('aria-label') ariaLabel: string;
344344

345345
/**
346346
* Users can specify the `aria-labelledby` attribute which will be forwarded to the input element

0 commit comments

Comments
 (0)