Skip to content

Commit b3f1ccf

Browse files
committed
address comments
1 parent dae035a commit b3f1ccf

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
lines changed

src/lib/datepicker/calendar-body.ts

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export class MatCalendarCell {
3939
styleUrls: ['calendar-body.css'],
4040
host: {
4141
'class': 'mat-calendar-body',
42+
'role': 'grid',
43+
'attr.aria-readonly': 'true'
4244
},
4345
exportAs: 'matCalendarBody',
4446
encapsulation: ViewEncapsulation.None,

src/lib/datepicker/calendar.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
[activeDate]="_activeDate"
3737
[selected]="selected"
3838
[dateFilter]="_dateFilterForViews"
39-
(selectedChange)="_monthSelected($event)">
39+
(selectedChange)="_goToDateInView($event, 'month')">
4040
</mat-year-view>
4141

4242
<mat-multi-year-view
4343
*ngSwitchCase="'multi-year'"
4444
[activeDate]="_activeDate"
4545
[selected]="selected"
4646
[dateFilter]="_dateFilterForViews"
47-
(selectedChange)="_yearSelected($event)">
47+
(selectedChange)="_goToDateInView($event, 'year')">
4848
</mat-multi-year-view>
4949
</div>

src/lib/datepicker/calendar.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
148148
if (this._currentView == 'year') {
149149
return this._dateAdapter.getYearName(this._activeDate);
150150
}
151-
let curYear = this._dateAdapter.getYear(this._activeDate);
152-
let firstYear = this._dateAdapter.getYearName(
153-
this._dateAdapter.createDate(curYear - curYear % 24, 0, 1));
154-
let lastYear = this._dateAdapter.getYearName(
155-
this._dateAdapter.createDate(curYear + yearsPerPage - 1 - curYear % 24, 0, 1));
156-
return `${firstYear} \u2013 ${lastYear}`;
151+
const activeYear = this._dateAdapter.getYear(this._activeDate);
152+
const firstYearInView = this._dateAdapter.getYearName(
153+
this._dateAdapter.createDate(activeYear - activeYear % 24, 0, 1));
154+
const lastYearInView = this._dateAdapter.getYearName(
155+
this._dateAdapter.createDate(activeYear + yearsPerPage - 1 - activeYear % 24, 0, 1));
156+
return `${firstYearInView} \u2013 ${lastYearInView}`;
157157
}
158158

159159
get _periodButtonLabel(): string {
@@ -231,15 +231,9 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
231231
}
232232

233233
/** Handles month selection in the multi-year view. */
234-
_yearSelected(year: D): void {
235-
this._activeDate = year;
236-
this._currentView = 'year';
237-
}
238-
239-
/** Handles month selection in the year view. */
240-
_monthSelected(month: D): void {
241-
this._activeDate = month;
242-
this._currentView = 'month';
234+
_goToDateInView(date: D, view: 'month' | 'year' | 'multi-year'): void {
235+
this._activeDate = date;
236+
this._currentView = view;
243237
}
244238

245239
/** Handles user clicks on the period label. */
@@ -308,6 +302,7 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
308302
if (this._currentView == 'year') {
309303
return this._dateAdapter.getYear(date1) == this._dateAdapter.getYear(date2);
310304
}
305+
// Otherwise we are in 'multi-year' view.
311306
return Math.floor(this._dateAdapter.getYear(date1) / yearsPerPage) ==
312307
Math.floor(this._dateAdapter.getYear(date2) / yearsPerPage);
313308
}
@@ -396,7 +391,7 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
396391
this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? 10 : 1);
397392
break;
398393
case ENTER:
399-
this._monthSelected(this._activeDate);
394+
this._goToDateInView(this._activeDate, 'month');
400395
break;
401396
default:
402397
// Don't prevent default or focus active cell on keys that we don't explicitly handle.
@@ -442,7 +437,7 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
442437
this._activeDate, event.altKey ? yearsPerPage * 10 : yearsPerPage);
443438
break;
444439
case ENTER:
445-
this._yearSelected(this._activeDate);
440+
this._goToDateInView(this._activeDate, 'year');
446441
break;
447442
default:
448443
// Don't prevent default or focus active cell on keys that we don't explicitly handle.

src/lib/datepicker/month-view.html

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<tr><th class="mat-calendar-table-header-divider" colspan="7" aria-hidden="true"></th></tr>
55
</thead>
66
<tbody mat-calendar-body
7-
role="grid"
87
[label]="_monthLabel"
98
[rows]="_weeks"
109
[todayValue]="_todayDate"

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

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<tr><th class="mat-calendar-table-header-divider" colspan="4"></th></tr>
44
</thead>
55
<tbody mat-calendar-body
6-
role="grid"
76
allowDisabledSelection="true"
87
[rows]="_years"
98
[todayValue]="_todayYear"

src/lib/datepicker/year-view.html

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<tr><th class="mat-calendar-table-header-divider" colspan="4"></th></tr>
44
</thead>
55
<tbody mat-calendar-body
6-
role="grid"
76
allowDisabledSelection="true"
87
[label]="_yearLabel"
98
[rows]="_months"

0 commit comments

Comments
 (0)