Skip to content

Commit cce33e4

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

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
@@ -304,6 +304,7 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
304304
case ENTER:
305305
if (this._dateFilterForViews(this._activeDate)) {
306306
this._dateSelected(this._activeDate);
307+
this._userSelected();
307308
// Prevent unexpected default actions such as form submission.
308309
event.preventDefault();
309310
}
@@ -367,22 +368,16 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
367368
* calendar table.
368369
*/
369370
private _prevMonthInSameCol(date: D): D {
370-
// Determine how many months to jump forward given that there are 2 empty slots at the beginning
371-
// of each year.
372-
let increment = this._dateAdapter.getMonth(date) <= 4 ? -5 :
373-
(this._dateAdapter.getMonth(date) >= 7 ? -7 : -12);
374-
return this._dateAdapter.addCalendarMonths(date, increment);
371+
// Decrement by 4 since there are 4 months per row.
372+
return this._dateAdapter.addCalendarMonths(date, -4);
375373
}
376374

377375
/**
378376
* Determine the date for the month that comes after the given month in the same column in the
379377
* calendar table.
380378
*/
381379
private _nextMonthInSameCol(date: D): D {
382-
// Determine how many months to jump forward given that there are 2 empty slots at the beginning
383-
// of each year.
384-
let increment = this._dateAdapter.getMonth(date) <= 4 ? 7 :
385-
(this._dateAdapter.getMonth(date) >= 7 ? 5 : 12);
386-
return this._dateAdapter.addCalendarMonths(date, increment);
380+
// Increment by 4 since there are 4 months per row.
381+
return this._dateAdapter.addCalendarMonths(date, 4);
387382
}
388383
}

0 commit comments

Comments
 (0)