Skip to content

Commit c43fb10

Browse files
committed
fix(datepicker): don't set aria-haspopup if no datepicker is set
Fixes the datepicker toggle and input setting `aria-haspopup`, even though they might not have a popup.
1 parent fce7205 commit c43fb10

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/lib/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-
'[attr.aria-haspopup]': 'true',
82+
'[attr.aria-haspopup]': '_datepicker ? true : 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/lib/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="true"
5+
[attr.aria-haspopup]="datepicker ? true : null"
66
[attr.aria-label]="_intl.openCalendarLabel"
77
[attr.tabindex]="disabled ? -1 : tabIndex"
88
[disabled]="disabled"

src/lib/datepicker/datepicker.spec.ts

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

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

15501573
describe('popup positioning', () => {
@@ -1990,3 +2013,10 @@ class DatepickerWithTabindexOnToggle {}
19902013
`,
19912014
})
19922015
class DatepickerToggleWithNoDatepicker {}
2016+
2017+
@Component({
2018+
template: `
2019+
<input [matDatepicker]="d">
2020+
`,
2021+
})
2022+
class DatepickerInputWithNoDatepicker {}

0 commit comments

Comments
 (0)