Skip to content

fix(material/radio): remove tabindex from host node #21280

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
Jan 19, 2021
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
12 changes: 1 addition & 11 deletions src/material-experimental/mdc-radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,17 +796,7 @@ describe('MDC-based MatRadio', () => {
const radioButtonEl =
predefinedFixture.debugElement.query(By.css('.mat-mdc-radio-button'))!.nativeElement;

expect(radioButtonEl.getAttribute('tabindex')).toBe('-1');
});

it('should set the tabindex to -1 on the host element', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was exactly the same as the one above so I removed it.

const predefinedFixture = TestBed.createComponent(RadioButtonWithPredefinedTabindex);
predefinedFixture.detectChanges();

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

expect(radioButtonEl.getAttribute('tabindex')).toBe('-1');
expect(radioButtonEl.hasAttribute('tabindex')).toBe(false);
});

it('should forward a pre-defined tabindex to the underlying input', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export class MatRadioGroup extends _MatRadioGroupBase<MatRadioButton> {
'[class.mat-primary]': 'color === "primary"',
'[class.mat-accent]': 'color === "accent"',
'[class.mat-warn]': 'color === "warn"',
'[attr.tabindex]': 'disabled ? null : -1',
// Needs to be removed since it causes some a11y issues (see #21266).
'[attr.tabindex]': 'null',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it specifically have to be null or can it just be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be null, because the tabindex can be set as <mat-radio tabindex="2"> which will set the input, but also keep the native attribute.

'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[attr.aria-describedby]': 'null',
Expand Down
2 changes: 1 addition & 1 deletion src/material/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ describe('MatRadio', () => {
const radioButtonEl =
predefinedFixture.debugElement.query(By.css('.mat-radio-button'))!.nativeElement;

expect(radioButtonEl.getAttribute('tabindex')).toBe('-1');
expect(radioButtonEl.hasAttribute('tabindex')).toBe(false);
});

it('should forward a pre-defined tabindex to the underlying input', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/material/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
'[class.mat-primary]': 'color === "primary"',
'[class.mat-accent]': 'color === "accent"',
'[class.mat-warn]': 'color === "warn"',
// Needs to be -1 so the `focus` event still fires.
'[attr.tabindex]': '-1',
// Needs to be removed since it causes some a11y issues (see #21266).
'[attr.tabindex]': 'null',
'[attr.id]': 'id',
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
Expand Down