Skip to content

Commit e8b4c49

Browse files
committed
fix(datepicker): keyboard fixes (enter matches click behavior & correct up and down arrow behavior in year mode).
1 parent 8f7c7cf commit e8b4c49

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/lib/datepicker/calendar.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
312312
case ENTER:
313313
if (this._dateFilterForViews(this._activeDate)) {
314314
this._dateSelected(this._activeDate);
315+
this._userSelected();
315316
// Prevent unexpected default actions such as form submission.
316317
event.preventDefault();
317318
}
@@ -375,23 +376,17 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
375376
* calendar table.
376377
*/
377378
private _prevMonthInSameCol(date: D): D {
378-
// Determine how many months to jump forward given that there are 2 empty slots at the beginning
379-
// of each year.
380-
let increment = this._dateAdapter.getMonth(date) <= 4 ? -5 :
381-
(this._dateAdapter.getMonth(date) >= 7 ? -7 : -12);
382-
return this._dateAdapter.addCalendarMonths(date, increment);
379+
// Decrement by 4 since there are 4 months per row.
380+
return this._dateAdapter.addCalendarMonths(date, -4);
383381
}
384382

385383
/**
386384
* Determine the date for the month that comes after the given month in the same column in the
387385
* calendar table.
388386
*/
389387
private _nextMonthInSameCol(date: D): D {
390-
// Determine how many months to jump forward given that there are 2 empty slots at the beginning
391-
// of each year.
392-
let increment = this._dateAdapter.getMonth(date) <= 4 ? 7 :
393-
(this._dateAdapter.getMonth(date) >= 7 ? 5 : 12);
394-
return this._dateAdapter.addCalendarMonths(date, increment);
388+
// Increment by 4 since there are 4 months per row.
389+
return this._dateAdapter.addCalendarMonths(date, 4);
395390
}
396391

397392
/**

0 commit comments

Comments
 (0)