Skip to content

Commit bd4597f

Browse files
crisbetoandrewseguin
authored andcommitted
fix(material/datepicker): clear tabindex from host node (#21633)
Similar to #21280. Removes the `tabindex` from the `mat-datepicker-toggle` host since it can caused accessibility issues. It was only there as a workaround which isn't required after #21046. (cherry picked from commit 2e783b4)
1 parent ba41912 commit bd4597f

File tree

2 files changed

+2
-29
lines changed

2 files changed

+2
-29
lines changed

src/material/datepicker/datepicker-toggle.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,12 @@ export class MatDatepickerToggleIcon {}
4141
styleUrls: ['datepicker-toggle.css'],
4242
host: {
4343
'class': 'mat-datepicker-toggle',
44-
// Always set the tabindex to -1 so that it doesn't overlap with any custom tabindex the
45-
// consumer may have provided, while still being able to receive focus.
46-
'[attr.tabindex]': 'disabled ? null : -1',
44+
'[attr.tabindex]': 'null',
4745
'[class.mat-datepicker-toggle-active]': 'datepicker && datepicker.opened',
4846
'[class.mat-accent]': 'datepicker && datepicker.color === "accent"',
4947
'[class.mat-warn]': 'datepicker && datepicker.color === "warn"',
5048
// Used by the test harness to tie this toggle to its datepicker.
5149
'[attr.data-mat-calendar]': 'datepicker ? datepicker.id : null',
52-
'(focus)': '_button.focus()',
5350
},
5451
exportAs: 'matDatepickerToggle',
5552
encapsulation: ViewEncapsulation.None,

src/material/datepicker/datepicker.spec.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,36 +1232,12 @@ describe('MatDatepicker', () => {
12321232
expect(button.getAttribute('tabindex')).toBe('7');
12331233
});
12341234

1235-
it('should reset the tabindex from the mat-datepicker-toggle host', () => {
1235+
it('should remove the tabindex from the mat-datepicker-toggle host', () => {
12361236
const fixture = createComponent(DatepickerWithTabindexOnToggle, [MatNativeDateModule]);
12371237
fixture.detectChanges();
12381238

12391239
const host = fixture.nativeElement.querySelector('.mat-datepicker-toggle');
12401240

1241-
expect(host.getAttribute('tabindex')).toBe('-1');
1242-
});
1243-
1244-
it('should forward focus to the underlying button when the host is focused', () => {
1245-
const fixture = createComponent(DatepickerWithTabindexOnToggle, [MatNativeDateModule]);
1246-
fixture.detectChanges();
1247-
1248-
const host = fixture.nativeElement.querySelector('.mat-datepicker-toggle');
1249-
const button = host.querySelector('button');
1250-
1251-
expect(document.activeElement).not.toBe(button);
1252-
1253-
host.focus();
1254-
1255-
expect(document.activeElement).toBe(button);
1256-
});
1257-
1258-
it('should remove the tabindex from the mat-datepicker-toggle host when disabled', () => {
1259-
const fixture = createComponent(DatepickerWithTabindexOnToggle, [MatNativeDateModule]);
1260-
fixture.componentInstance.disabled = true;
1261-
fixture.detectChanges();
1262-
1263-
const host = fixture.nativeElement.querySelector('.mat-datepicker-toggle');
1264-
12651241
expect(host.hasAttribute('tabindex')).toBe(false);
12661242
});
12671243

0 commit comments

Comments
 (0)