Skip to content

fix(datepicker): don't set aria-haspopup if no datepicker is set #15554

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
Aug 21, 2019
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
2 changes: 1 addition & 1 deletion src/material/datepicker/datepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class MatDatepickerInputEvent<D> {
{provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: MatDatepickerInput},
],
host: {
'aria-haspopup': 'dialog',
'[attr.aria-haspopup]': '_datepicker ? "dialog" : null',
'[attr.aria-owns]': '(_datepicker?.opened && _datepicker.id) || null',
'[attr.min]': 'min ? _dateAdapter.toIso8601(min) : null',
'[attr.max]': 'max ? _dateAdapter.toIso8601(max) : null',
Expand Down
2 changes: 1 addition & 1 deletion src/material/datepicker/datepicker-toggle.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#button
mat-icon-button
type="button"
aria-haspopup="dialog"
[attr.aria-haspopup]="datepicker ? 'dialog' : null"
[attr.aria-label]="_intl.openCalendarLabel"
[attr.tabindex]="disabled ? -1 : tabIndex"
[disabled]="disabled"
Expand Down
32 changes: 31 additions & 1 deletion src/material/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1538,13 +1538,36 @@ describe('MatDatepicker', () => {
});
});

describe('datepicker toggle without a datepicker', () => {
describe('datepicker directives without a datepicker', () => {
it('should not throw on init if toggle does not have a datepicker', () => {
expect(() => {
const fixture = createComponent(DatepickerToggleWithNoDatepicker, [MatNativeDateModule]);
fixture.detectChanges();
}).not.toThrow();
});

it('should not set aria-haspopup if toggle does not have a datepicker', () => {
const fixture = createComponent(DatepickerToggleWithNoDatepicker, [MatNativeDateModule]);
fixture.detectChanges();
const toggle = fixture.nativeElement.querySelector('.mat-datepicker-toggle button');

expect(toggle.hasAttribute('aria-haspopup')).toBe(false);
});

it('should not throw on init if input does not have a datepicker', () => {
expect(() => {
const fixture = createComponent(DatepickerInputWithNoDatepicker, [MatNativeDateModule]);
fixture.detectChanges();
}).not.toThrow();
});

it('should not set aria-haspopup if input does not have a datepicker', () => {
const fixture = createComponent(DatepickerInputWithNoDatepicker, [MatNativeDateModule]);
fixture.detectChanges();
const toggle = fixture.nativeElement.querySelector('input');

expect(toggle.hasAttribute('aria-haspopup')).toBe(false);
});
});

describe('popup positioning', () => {
Expand Down Expand Up @@ -1990,3 +2013,10 @@ class DatepickerWithTabindexOnToggle {}
`,
})
class DatepickerToggleWithNoDatepicker {}

@Component({
template: `
<input [matDatepicker]="d">
`,
})
class DatepickerInputWithNoDatepicker {}