Skip to content

fix(material/datepicker): clear tabindex from host node #21633

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
Jan 25, 2021
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
5 changes: 1 addition & 4 deletions src/material/datepicker/datepicker-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ export class MatDatepickerToggleIcon {}
styleUrls: ['datepicker-toggle.css'],
host: {
'class': 'mat-datepicker-toggle',
// Always set the tabindex to -1 so that it doesn't overlap with any custom tabindex the
// consumer may have provided, while still being able to receive focus.
'[attr.tabindex]': 'disabled ? null : -1',
'[attr.tabindex]': 'null',
'[class.mat-datepicker-toggle-active]': 'datepicker && datepicker.opened',
'[class.mat-accent]': 'datepicker && datepicker.color === "accent"',
'[class.mat-warn]': 'datepicker && datepicker.color === "warn"',
// Used by the test harness to tie this toggle to its datepicker.
'[attr.data-mat-calendar]': 'datepicker ? datepicker.id : null',
'(focus)': '_button.focus()',
},
exportAs: 'matDatepickerToggle',
encapsulation: ViewEncapsulation.None,
Expand Down
26 changes: 1 addition & 25 deletions src/material/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,36 +1238,12 @@ describe('MatDatepicker', () => {
expect(button.getAttribute('tabindex')).toBe('7');
});

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

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

expect(host.getAttribute('tabindex')).toBe('-1');
});

it('should forward focus to the underlying button when the host is focused', () => {
const fixture = createComponent(DatepickerWithTabindexOnToggle, [MatNativeDateModule]);
fixture.detectChanges();

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

expect(document.activeElement).not.toBe(button);

host.focus();

expect(document.activeElement).toBe(button);
});

it('should remove the tabindex from the mat-datepicker-toggle host when disabled', () => {
const fixture = createComponent(DatepickerWithTabindexOnToggle, [MatNativeDateModule]);
fixture.componentInstance.disabled = true;
fixture.detectChanges();

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

expect(host.hasAttribute('tabindex')).toBe(false);
});

Expand Down