Skip to content

Commit e91f0a1

Browse files
committed
fix(radio): host element unable to receive focus events
In #13323 we started clearing the `tabindex` from the `host` element in order to avoid having two elements with the same `tabindex` when the consumer sets a custom `tabindex`. As a result, the `mat-radio-button` can no longer receive focus and forward it to the `input`. These changes always reset the `tabindex` to -1 so the element is focusable, but not tabbable. Fixes #13953.
1 parent 76044e8 commit e91f0a1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/lib/radio/radio.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ describe('MatRadio', () => {
723723
const radioButtonEl =
724724
predefinedFixture.debugElement.query(By.css('.mat-radio-button')).nativeElement;
725725

726-
expect(radioButtonEl.getAttribute('tabindex')).toBeFalsy();
726+
expect(radioButtonEl.getAttribute('tabindex')).toBe('-1');
727727
});
728728

729729
});

src/lib/radio/radio.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ export const _MatRadioButtonMixinBase:
336336
'[class.mat-radio-checked]': 'checked',
337337
'[class.mat-radio-disabled]': 'disabled',
338338
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
339-
'[attr.tabindex]': 'null',
339+
// Needs to be -1 so the `focus` event still fires.
340+
'[attr.tabindex]': '-1',
340341
'[attr.id]': 'id',
341342
// Note: under normal conditions focus shouldn't land on this element, however it may be
342343
// programmatically set, for example inside of a focus trap, in this case we want to forward

0 commit comments

Comments
 (0)