Skip to content

Commit afeb744

Browse files
committed
fix(datepicker): make date range aria-live and fix active date logic
1 parent 0b7572b commit afeb744

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

src/lib/datepicker/calendar-header.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<div class="mat-calendar-header">
22
<div class="mat-calendar-controls">
33
<button mat-button type="button" class="mat-calendar-period-button"
4-
(click)="currentPeriodClicked()" [attr.aria-label]="periodButtonLabel">
4+
(click)="currentPeriodClicked()" [attr.aria-label]="periodButtonLabel"
5+
aria-live="polite">
56
{{periodButtonText}}
6-
<div class="mat-calendar-arrow" [class.mat-calendar-invert]="calendar.currentView != 'month'"></div>
7+
<div class="mat-calendar-arrow"
8+
[class.mat-calendar-invert]="calendar.currentView != 'month'"></div>
79
</button>
810

911
<div class="mat-calendar-spacer"></div>

src/lib/datepicker/calendar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<mat-year-view
1717
*ngSwitchCase="'year'"
18-
[activeDate]="activeDate"
18+
[(activeDate)]="activeDate"
1919
[selected]="selected"
2020
[dateFilter]="dateFilter"
2121
[maxDate]="maxDate"
@@ -26,7 +26,7 @@
2626

2727
<mat-multi-year-view
2828
*ngSwitchCase="'multi-year'"
29-
[activeDate]="activeDate"
29+
[(activeDate)]="activeDate"
3030
[selected]="selected"
3131
[dateFilter]="dateFilter"
3232
[maxDate]="maxDate"

src/lib/datepicker/month-view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ export class MatMonthView<D> implements AfterContentInit {
178178
// navigation should skip over disabled dates, and if so, how to implement that efficiently.
179179

180180
const oldActiveDate = this._activeDate;
181-
182181
const isRtl = this._isRtl();
182+
183183
switch (event.keyCode) {
184184
case LEFT_ARROW:
185185
this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, isRtl ? 1 : -1);

src/lib/datepicker/multi-year-view.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ export class MatMultiYearView<D> implements AfterContentInit {
101101
/** Emits the selected year. This doesn't imply a change on the selected date */
102102
@Output() readonly yearSelected: EventEmitter<D> = new EventEmitter<D>();
103103

104+
/** Emits when any date is activated. */
105+
@Output() readonly activeDateChange: EventEmitter<D> = new EventEmitter<D>();
106+
104107
/** The body of calendar table */
105108
@ViewChild(MatCalendarBody) _matCalendarBody;
106109

@@ -160,6 +163,7 @@ export class MatMultiYearView<D> implements AfterContentInit {
160163
// disabled ones from being selected. This may not be ideal, we should look into whether
161164
// navigation should skip over disabled dates, and if so, how to implement that efficiently.
162165

166+
const oldActiveDate = this._activeDate;
163167
const isRtl = this._isRtl();
164168

165169
switch (event.keyCode) {
@@ -201,6 +205,10 @@ export class MatMultiYearView<D> implements AfterContentInit {
201205
return;
202206
}
203207

208+
if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
209+
this.activeDateChange.emit(this.activeDate);
210+
}
211+
204212
this._focusActiveCell();
205213
// Prevent unexpected default actions such as form submission.
206214
event.preventDefault();

src/lib/datepicker/year-view.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ export class MatYearView<D> implements AfterContentInit {
9696
/** Emits the selected month. This doesn't imply a change on the selected date */
9797
@Output() readonly monthSelected: EventEmitter<D> = new EventEmitter<D>();
9898

99+
/** Emits when any date is activated. */
100+
@Output() readonly activeDateChange: EventEmitter<D> = new EventEmitter<D>();
101+
99102
/** The body of calendar table */
100103
@ViewChild(MatCalendarBody) _matCalendarBody;
101104

@@ -153,6 +156,7 @@ export class MatYearView<D> implements AfterContentInit {
153156
// disabled ones from being selected. This may not be ideal, we should look into whether
154157
// navigation should skip over disabled dates, and if so, how to implement that efficiently.
155158

159+
const oldActiveDate = this._activeDate;
156160
const isRtl = this._isRtl();
157161

158162
switch (event.keyCode) {
@@ -192,6 +196,10 @@ export class MatYearView<D> implements AfterContentInit {
192196
return;
193197
}
194198

199+
if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
200+
this.activeDateChange.emit(this.activeDate);
201+
}
202+
195203
this._focusActiveCell();
196204
// Prevent unexpected default actions such as form submission.
197205
event.preventDefault();

0 commit comments

Comments
 (0)