Skip to content
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