Skip to content

Commit 2e783b4

Browse files
authored
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.
1 parent 9e87050 commit 2e783b4

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
@@ -1258,36 +1258,12 @@ describe('MatDatepicker', () => {
12581258
expect(button.getAttribute('tabindex')).toBe('7');
12591259
});
12601260

1261-
it('should reset the tabindex from the mat-datepicker-toggle host', () => {
1261+
it('should remove the tabindex from the mat-datepicker-toggle host', () => {
12621262
const fixture = createComponent(DatepickerWithTabindexOnToggle, [MatNativeDateModule]);
12631263
fixture.detectChanges();
12641264

12651265
const host = fixture.nativeElement.querySelector('.mat-datepicker-toggle');
12661266

1267-
expect(host.getAttribute('tabindex')).toBe('-1');
1268-
});
1269-
1270-
it('should forward focus to the underlying button when the host is focused', () => {
1271-
const fixture = createComponent(DatepickerWithTabindexOnToggle, [MatNativeDateModule]);
1272-
fixture.detectChanges();
1273-
1274-
const host = fixture.nativeElement.querySelector('.mat-datepicker-toggle');
1275-
const button = host.querySelector('button');
1276-
1277-
expect(document.activeElement).not.toBe(button);
1278-
1279-
host.focus();
1280-
1281-
expect(document.activeElement).toBe(button);
1282-
});
1283-
1284-
it('should remove the tabindex from the mat-datepicker-toggle host when disabled', () => {
1285-
const fixture = createComponent(DatepickerWithTabindexOnToggle, [MatNativeDateModule]);
1286-
fixture.componentInstance.disabled = true;
1287-
fixture.detectChanges();
1288-
1289-
const host = fixture.nativeElement.querySelector('.mat-datepicker-toggle');
1290-
12911267
expect(host.hasAttribute('tabindex')).toBe(false);
12921268
});
12931269

0 commit comments

Comments
 (0)