Skip to content

Commit 845388c

Browse files
crisbetojelbourn
authored andcommitted
fix(checkbox): clear tabindex from host element (#13308)
Currently we forward the tabindex from the host element to the underlying input, however we leave behind the tabindex on the host, which means that consumers can end up with two layers of focusable elements.
1 parent 92a5f0e commit 845388c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/lib/checkbox/checkbox.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,14 @@ describe('MatCheckbox', () => {
784784
expect(checkbox.tabIndex)
785785
.toBe(5, 'Expected tabIndex property to have been set based on the native attribute');
786786
}));
787+
788+
it('should clear the tabindex attribute from the host element', () => {
789+
fixture = createComponent(CheckboxWithTabindexAttr);
790+
fixture.detectChanges();
791+
792+
const checkbox = fixture.debugElement.query(By.directive(MatCheckbox)).nativeElement;
793+
expect(checkbox.getAttribute('tabindex')).toBeFalsy();
794+
});
787795
});
788796

789797
describe('using ViewChild', () => {

src/lib/checkbox/checkbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const _MatCheckboxMixinBase:
119119
host: {
120120
'class': 'mat-checkbox',
121121
'[id]': 'id',
122+
'[attr.tabindex]': 'null',
122123
'[class.mat-checkbox-indeterminate]': 'indeterminate',
123124
'[class.mat-checkbox-checked]': 'checked',
124125
'[class.mat-checkbox-disabled]': 'disabled',

0 commit comments

Comments
 (0)