Skip to content

fix(radio): clear aria attributes from host node #16938

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
Sep 9, 2019
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
23 changes: 23 additions & 0 deletions src/material/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('MatRadio', () => {
InterleavedRadioGroup,
TranscludingWrapper,
RadioButtonWithPredefinedTabindex,
RadioButtonWithPredefinedAriaAttributes,
]
});

Expand Down Expand Up @@ -778,6 +779,18 @@ describe('MatRadio', () => {
expect(radioButtonEl.getAttribute('tabindex')).toBe('-1');
});

it('should remove the aria attributes from the host element', () => {
const predefinedFixture = TestBed.createComponent(RadioButtonWithPredefinedAriaAttributes);
predefinedFixture.detectChanges();

const radioButtonEl =
predefinedFixture.debugElement.query(By.css('.mat-radio-button'))!.nativeElement;

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

});

describe('group interspersed with other tags', () => {
Expand Down Expand Up @@ -991,3 +1004,13 @@ class DefaultRadioButton {}
template: `<mat-radio-button color="warn"></mat-radio-button>`
})
class RadioButtonWithColorBinding {}


@Component({
template: `
<mat-radio-button
aria-label="Radio button"
aria-describedby="something"
aria-labelledby="something-else"></mat-radio-button>`
})
class RadioButtonWithPredefinedAriaAttributes {}
3 changes: 3 additions & 0 deletions src/material/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ const _MatRadioButtonMixinBase:
// Needs to be -1 so the `focus` event still fires.
'[attr.tabindex]': '-1',
'[attr.id]': 'id',
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[attr.aria-describedby]': 'null',
// Note: under normal conditions focus shouldn't land on this element, however it may be
// programmatically set, for example inside of a focus trap, in this case we want to forward
// the focus to the native element.
Expand Down