Skip to content

fix(radio): clear tabindex from host element #13323

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
Sep 27, 2018
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
20 changes: 19 additions & 1 deletion src/lib/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe('MatRadio', () => {
RadioGroupWithFormControl,
StandaloneRadioButtons,
InterleavedRadioGroup,
TranscludingWrapper
TranscludingWrapper,
RadioButtonWithPredefinedTabindex,
]
});

Expand Down Expand Up @@ -714,6 +715,17 @@ describe('MatRadio', () => {
expect(radioButtonInput.tabIndex)
.toBe(4, 'Expected the tabindex to be set to "4".');
});

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

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

expect(radioButtonEl.getAttribute('tabindex')).toBeFalsy();
});

});

describe('group interspersed with other tags', () => {
Expand Down Expand Up @@ -873,3 +885,9 @@ class InterleavedRadioGroup {
`
})
class TranscludingWrapper {}


@Component({
template: `<mat-radio-button tabindex="0"></mat-radio-button>`
})
class RadioButtonWithPredefinedTabindex {}
1 change: 1 addition & 0 deletions src/lib/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export const _MatRadioButtonMixinBase:
'[class.mat-radio-checked]': 'checked',
'[class.mat-radio-disabled]': 'disabled',
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
'[attr.tabindex]': 'null',
'[attr.id]': 'id',
// Note: under normal conditions focus shouldn't land on this element, however it may be
// programmatically set, for example inside of a focus trap, in this case we want to forward
Expand Down