Skip to content

Commit d17883c

Browse files
crisbetommalerba
authored andcommitted
fix(material/radio): remove tabindex from host node (#21280)
Removes the `tabindex` from the host node, because it causes some a11y issues. We had it there before so that things like `cdkFocusInitial` would work, but after #21046 it isn't necessary anymore. Fixes #21266. (cherry picked from commit cdfc46b)
1 parent fd547f4 commit d17883c

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

src/material-experimental/mdc-radio/radio.spec.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -796,17 +796,7 @@ describe('MDC-based MatRadio', () => {
796796
const radioButtonEl =
797797
predefinedFixture.debugElement.query(By.css('.mat-mdc-radio-button'))!.nativeElement;
798798

799-
expect(radioButtonEl.getAttribute('tabindex')).toBe('-1');
800-
});
801-
802-
it('should set the tabindex to -1 on the host element', () => {
803-
const predefinedFixture = TestBed.createComponent(RadioButtonWithPredefinedTabindex);
804-
predefinedFixture.detectChanges();
805-
806-
const radioButtonEl =
807-
predefinedFixture.debugElement.query(By.css('.mat-mdc-radio-button'))!.nativeElement;
808-
809-
expect(radioButtonEl.getAttribute('tabindex')).toBe('-1');
799+
expect(radioButtonEl.hasAttribute('tabindex')).toBe(false);
810800
});
811801

812802
it('should forward a pre-defined tabindex to the underlying input', () => {

src/material-experimental/mdc-radio/radio.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export class MatRadioGroup extends _MatRadioGroupBase<MatRadioButton> {
9797
'[class.mat-primary]': 'color === "primary"',
9898
'[class.mat-accent]': 'color === "accent"',
9999
'[class.mat-warn]': 'color === "warn"',
100-
'[attr.tabindex]': 'disabled ? null : -1',
100+
// Needs to be removed since it causes some a11y issues (see #21266).
101+
'[attr.tabindex]': 'null',
101102
'[attr.aria-label]': 'null',
102103
'[attr.aria-labelledby]': 'null',
103104
'[attr.aria-describedby]': 'null',

src/material/radio/radio.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ describe('MatRadio', () => {
790790
const radioButtonEl =
791791
predefinedFixture.debugElement.query(By.css('.mat-radio-button'))!.nativeElement;
792792

793-
expect(radioButtonEl.getAttribute('tabindex')).toBe('-1');
793+
expect(radioButtonEl.hasAttribute('tabindex')).toBe(false);
794794
});
795795

796796
it('should forward a pre-defined tabindex to the underlying input', () => {

src/material/radio/radio.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
640640
'[class.mat-primary]': 'color === "primary"',
641641
'[class.mat-accent]': 'color === "accent"',
642642
'[class.mat-warn]': 'color === "warn"',
643-
// Needs to be -1 so the `focus` event still fires.
644-
'[attr.tabindex]': '-1',
643+
// Needs to be removed since it causes some a11y issues (see #21266).
644+
'[attr.tabindex]': 'null',
645645
'[attr.id]': 'id',
646646
'[attr.aria-label]': 'null',
647647
'[attr.aria-labelledby]': 'null',

0 commit comments

Comments
 (0)