Skip to content

Commit f590dc6

Browse files
crisbetoandrewseguin
authored andcommitted
fix(datepicker): don't set aria-haspopup if no datepicker is set (#15554)
Fixes the datepicker toggle and input setting `aria-haspopup`, even though they might not have a popup. (cherry picked from commit 1b7dc89)
1 parent 2585a8a commit f590dc6

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/material/datepicker/datepicker-input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class MatDatepickerInputEvent<D> {
7979
{provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: MatDatepickerInput},
8080
],
8181
host: {
82-
'aria-haspopup': 'dialog',
82+
'[attr.aria-haspopup]': '_datepicker ? "dialog" : null',
8383
'[attr.aria-owns]': '(_datepicker?.opened && _datepicker.id) || null',
8484
'[attr.min]': 'min ? _dateAdapter.toIso8601(min) : null',
8585
'[attr.max]': 'max ? _dateAdapter.toIso8601(max) : null',

src/material/datepicker/datepicker-toggle.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#button
33
mat-icon-button
44
type="button"
5-
aria-haspopup="dialog"
5+
[attr.aria-haspopup]="datepicker ? 'dialog' : null"
66
[attr.aria-label]="_intl.openCalendarLabel"
77
[attr.tabindex]="disabled ? -1 : tabIndex"
88
[disabled]="disabled"

src/material/datepicker/datepicker.spec.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,13 +1539,36 @@ describe('MatDatepicker', () => {
15391539
});
15401540
});
15411541

1542-
describe('datepicker toggle without a datepicker', () => {
1542+
describe('datepicker directives without a datepicker', () => {
15431543
it('should not throw on init if toggle does not have a datepicker', () => {
15441544
expect(() => {
15451545
const fixture = createComponent(DatepickerToggleWithNoDatepicker, [MatNativeDateModule]);
15461546
fixture.detectChanges();
15471547
}).not.toThrow();
15481548
});
1549+
1550+
it('should not set aria-haspopup if toggle does not have a datepicker', () => {
1551+
const fixture = createComponent(DatepickerToggleWithNoDatepicker, [MatNativeDateModule]);
1552+
fixture.detectChanges();
1553+
const toggle = fixture.nativeElement.querySelector('.mat-datepicker-toggle button');
1554+
1555+
expect(toggle.hasAttribute('aria-haspopup')).toBe(false);
1556+
});
1557+
1558+
it('should not throw on init if input does not have a datepicker', () => {
1559+
expect(() => {
1560+
const fixture = createComponent(DatepickerInputWithNoDatepicker, [MatNativeDateModule]);
1561+
fixture.detectChanges();
1562+
}).not.toThrow();
1563+
});
1564+
1565+
it('should not set aria-haspopup if input does not have a datepicker', () => {
1566+
const fixture = createComponent(DatepickerInputWithNoDatepicker, [MatNativeDateModule]);
1567+
fixture.detectChanges();
1568+
const toggle = fixture.nativeElement.querySelector('input');
1569+
1570+
expect(toggle.hasAttribute('aria-haspopup')).toBe(false);
1571+
});
15491572
});
15501573

15511574
describe('popup positioning', () => {
@@ -1991,3 +2014,10 @@ class DatepickerWithTabindexOnToggle {}
19912014
`,
19922015
})
19932016
class DatepickerToggleWithNoDatepicker {}
2017+
2018+
@Component({
2019+
template: `
2020+
<input [matDatepicker]="d">
2021+
`,
2022+
})
2023+
class DatepickerInputWithNoDatepicker {}

0 commit comments

Comments
 (0)