Skip to content

fix(material-experimental/mdc-radio): able to focus disabled radio button via click #18584

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
Feb 26, 2020
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
14 changes: 12 additions & 2 deletions src/material-experimental/mdc-radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ describe('MDC-based 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 All @@ -798,6 +798,15 @@ describe('MDC-based MatRadio', () => {
expect(radioButtonEl.hasAttribute('aria-labelledby')).toBe(false);
});

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

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

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

});

describe('group interspersed with other tags', () => {
Expand Down Expand Up @@ -964,10 +973,11 @@ class RadioGroupWithFormControl {
}

@Component({
template: `<mat-radio-button [tabIndex]="tabIndex"></mat-radio-button>`
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-experimental/mdc-radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class MatRadioGroup extends BaseMatRadioGroup {
'[class.mat-primary]': 'color === "primary"',
'[class.mat-accent]': 'color === "accent"',
'[class.mat-warn]': 'color === "warn"',
'[attr.tabindex]': '-1',
'[attr.tabindex]': 'disabled ? null : -1',
'[attr.aria-label]': 'null',
'[attr.aria-labelledby]': 'null',
'[attr.aria-describedby]': 'null',
Expand Down