Skip to content

fix(material/radio): able to focus disabled radio button via click #15499

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 13 additions & 4 deletions src/material/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ describe('MatRadio', () => {
.toBe(4, 'Expected the tabindex to be set to "4".');
});

it('should remove the tabindex from the host element', () => {
it('should set the tabindex to -1 on the host element', () => {
const predefinedFixture = TestBed.createComponent(RadioButtonWithPredefinedTabindex);
predefinedFixture.detectChanges();

Expand Down Expand Up @@ -815,6 +815,15 @@ describe('MatRadio', () => {
expect(radioButtonEl.hasAttribute('aria-labelledby')).toBe(false);
});

it('should remove the tabindex from the host element when disabled', () => {
const radioButtonEl = fixture.debugElement.query(By.css('.mat-radio-button')).nativeElement;

fixture.componentInstance.disabled = true;
fixture.detectChanges();

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

});

describe('group interspersed with other tags', () => {
Expand Down Expand Up @@ -982,11 +991,11 @@ class RadioGroupWithFormControl {
formControl = new FormControl();
}

@Component({
template: `<mat-radio-button [tabIndex]="tabIndex"></mat-radio-button>`
})
@Component(
{template: `<mat-radio-button [disabled]="disabled" [tabIndex]="tabIndex"></mat-radio-button>`})
class FocusableRadioButton {
tabIndex: number;
disabled = false;
}

@Component({
Expand Down
2 changes: 1 addition & 1 deletion src/material/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
'[class.mat-accent]': 'color === "accent"',
'[class.mat-warn]': 'color === "warn"',
// Needs to be -1 so the `focus` event still fires.
'[attr.tabindex]': '-1',
'[attr.tabindex]': 'disabled ? null : -1',
'[attr.id]': 'id',
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
Expand Down