@@ -230,9 +230,7 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
230
230
/** Handles when a new date is selected. */
231
231
_dateSelected ( event : MatCalendarUserEvent < number > ) {
232
232
const date = event . value ;
233
- const selectedYear = this . _dateAdapter . getYear ( this . activeDate ) ;
234
- const selectedMonth = this . _dateAdapter . getMonth ( this . activeDate ) ;
235
- const selectedDate = this . _dateAdapter . createDate ( selectedYear , selectedMonth , date ) ;
233
+ const selectedDate = this . _normalizeDate ( date ) ;
236
234
let rangeStartDate : number | null ;
237
235
let rangeEndDate : number | null ;
238
236
@@ -252,8 +250,30 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
252
250
this . _changeDetectorRef . markForCheck ( ) ;
253
251
}
254
252
253
+ private _normalizeDate ( date : number ) : D {
254
+ const normalizedYear = this . _dateAdapter . getYear ( this . activeDate ) ;
255
+ const normalizedMonth = this . _dateAdapter . getMonth ( this . activeDate ) ;
256
+ const normalizedDate = this . _dateAdapter . createDate ( normalizedYear , normalizedMonth , date ) ;
257
+ return normalizedDate ;
258
+ }
259
+
260
+ /** Handles when a new date becomes active. */
261
+ _dateBecomesActive ( event : MatCalendarUserEvent < number > ) {
262
+ console . log ( '_dateBecomesActive' , event . value ) ;
263
+ const date = event . value ;
264
+ const oldActiveDate = this . activeDate ;
265
+ this . activeDate = this . _normalizeDate ( date ) ;
266
+
267
+ if ( this . _dateAdapter . compareDate ( oldActiveDate , this . activeDate ) ) {
268
+ this . activeDateChange . emit ( this . _activeDate ) ;
269
+ console . log ( 'schedule in _dateBecomesActive' , this . _activeDate ) ;
270
+ this . _focusActiveCellAfterViewChecked ( ) ;
271
+ }
272
+ }
273
+
255
274
/** Handles keydown events on the calendar body when calendar is in month view. */
256
275
_handleCalendarBodyKeydown ( event : KeyboardEvent ) : void {
276
+ console . log ( '_handleCalendarBodyKeydown' , event . key ) ;
257
277
// TODO(mmalerba): We currently allow keyboard navigation to disabled dates, but just prevent
258
278
// disabled ones from being selected. This may not be ideal, we should look into whether
259
279
// navigation should skip over disabled dates, and if so, how to implement that efficiently.
@@ -327,9 +347,10 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
327
347
328
348
if ( this . _dateAdapter . compareDate ( oldActiveDate , this . activeDate ) ) {
329
349
this . activeDateChange . emit ( this . activeDate ) ;
350
+ console . log ( 'scheduling in keydown handler' , this . _activeDate ) ;
351
+ this . _focusActiveCellAfterViewChecked ( ) ;
330
352
}
331
353
332
- this . _focusActiveCellAfterViewChecked ( ) ;
333
354
// Prevent unexpected default actions such as form submission.
334
355
event . preventDefault ( ) ;
335
356
}
0 commit comments