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