Skip to content

Commit 197ba5e

Browse files
committed
fix(datepicker): make date range aria-live and fix active date logic
1 parent 69e4ca7 commit 197ba5e

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
@@ -177,8 +177,8 @@ export class MatMonthView<D> implements AfterContentInit {
177177
// navigation should skip over disabled dates, and if so, how to implement that efficiently.
178178

179179
const oldActiveDate = this._activeDate;
180-
181180
const isRtl = this._isRtl();
181+
182182
switch (event.keyCode) {
183183
case LEFT_ARROW:
184184
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: MatCalendarBody;
106109

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

165+
const oldActiveDate = this._activeDate;
162166
const isRtl = this._isRtl();
163167

164168
switch (event.keyCode) {
@@ -200,6 +204,10 @@ export class MatMultiYearView<D> implements AfterContentInit {
200204
return;
201205
}
202206

207+
if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
208+
this.activeDateChange.emit(this.activeDate);
209+
}
210+
203211
this._focusActiveCell();
204212
// Prevent unexpected default actions such as form submission.
205213
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: MatCalendarBody;
101104

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

158+
const oldActiveDate = this._activeDate;
155159
const isRtl = this._isRtl();
156160

157161
switch (event.keyCode) {
@@ -191,6 +195,10 @@ export class MatYearView<D> implements AfterContentInit {
191195
return;
192196
}
193197

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

0 commit comments

Comments
 (0)