Skip to content

Commit

Permalink
fix(button-toggle): setting blank aria-label attribute by default (#1…
Browse files Browse the repository at this point in the history
…0605)

Fixes the button toggle setting the `aria-label` of its underlying input to a blank value by default.
  • Loading branch information
crisbeto authored and jelbourn committed Apr 5, 2018
1 parent b38b966 commit 95dba59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/lib/button-toggle/button-toggle.spec.ts
Expand Up @@ -622,16 +622,22 @@ describe('MatButtonToggle without forms', () => {

});

describe('with provided aria-label ', () => {
let checkboxDebugElement: DebugElement;
let checkboxNativeElement: HTMLElement;
let inputElement: HTMLInputElement;
describe('aria-label handling ', () => {
it('should not set the aria-label attribute if none is provided', () => {
let fixture = TestBed.createComponent(StandaloneButtonToggle);
let checkboxDebugElement = fixture.debugElement.query(By.directive(MatButtonToggle));
let checkboxNativeElement = checkboxDebugElement.nativeElement;
let inputElement = checkboxNativeElement.querySelector('input') as HTMLInputElement;

fixture.detectChanges();
expect(inputElement.hasAttribute('aria-label')).toBe(false);
});

it('should use the provided aria-label', () => {
let fixture = TestBed.createComponent(ButtonToggleWithAriaLabel);
checkboxDebugElement = fixture.debugElement.query(By.directive(MatButtonToggle));
checkboxNativeElement = checkboxDebugElement.nativeElement;
inputElement = checkboxNativeElement.querySelector('input') as HTMLInputElement;
let checkboxDebugElement = fixture.debugElement.query(By.directive(MatButtonToggle));
let checkboxNativeElement = checkboxDebugElement.nativeElement;
let inputElement = checkboxNativeElement.querySelector('input') as HTMLInputElement;

fixture.detectChanges();
expect(inputElement.getAttribute('aria-label')).toBe('Super effective');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/button-toggle/button-toggle.ts
Expand Up @@ -340,7 +340,7 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
* Attached to the aria-label attribute of the host element. In most cases, arial-labelledby will
* take precedence so this may be omitted.
*/
@Input('aria-label') ariaLabel: string = '';
@Input('aria-label') ariaLabel: string;

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

0 comments on commit 95dba59

Please sign in to comment.