Skip to content

fix(button-toggle): clear static aria attributes from host nodes #17086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/material/button-toggle/button-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ describe('MatButtonToggle without forms', () => {
ButtonToggleWithTabindex,
ButtonToggleWithStaticName,
ButtonToggleWithStaticChecked,
ButtonToggleWithStaticAriaAttributes,
],
});

Expand Down Expand Up @@ -756,6 +757,16 @@ describe('MatButtonToggle without forms', () => {
fixture.detectChanges();
expect(buttonElement.getAttribute('aria-label')).toBe('Super effective');
});

it('should clear the static aria from the host node', () => {
const fixture = TestBed.createComponent(ButtonToggleWithStaticAriaAttributes);
fixture.detectChanges();
const hostNode: HTMLElement = fixture.nativeElement.querySelector('mat-button-toggle');

expect(hostNode.hasAttribute('aria-label')).toBe(false);
expect(hostNode.hasAttribute('aria-labelledby')).toBe(false);
});

});

describe('with provided aria-labelledby ', () => {
Expand Down Expand Up @@ -1073,3 +1084,11 @@ class ButtonToggleWithStaticChecked {
@ViewChild(MatButtonToggleGroup) group: MatButtonToggleGroup;
@ViewChildren(MatButtonToggle) toggles: QueryList<MatButtonToggle>;
}


@Component({
template: `
<mat-button-toggle aria-label="Toggle me" aria-labelledby="something"></mat-button-toggle>
`
})
class ButtonToggleWithStaticAriaAttributes {}
2 changes: 2 additions & 0 deletions src/material/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ const _MatButtonToggleMixinBase: CanDisableRippleCtor & typeof MatButtonToggleBa
// Always reset the tabindex to -1 so it doesn't conflict with the one on the `button`,
// but can still receive focus from things like cdkFocusInitial.
'[attr.tabindex]': '-1',
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[attr.id]': 'id',
'[attr.name]': 'null',
'(focus)': 'focus()',
Expand Down