@@ -230,7 +230,9 @@ 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 selectedDate = this . _getDateFromDayOfMonth ( date ) ;
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 ) ;
234
236
let rangeStartDate : number | null ;
235
237
let rangeEndDate : number | null ;
236
238
@@ -250,26 +252,6 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
250
252
this . _changeDetectorRef . markForCheck ( ) ;
251
253
}
252
254
253
- /**
254
- * Takes the index of a calendar body cell wrapped in in an event as argument. For the date that
255
- * corresponds to the given cell, set `activeDate` to that date and fire `activeDateChange` with
256
- * that date.
257
- *
258
- * This fucntion is used to match each component's model of the active date with the calendar
259
- * body cell that was focused. It updates its value of `activeDate` synchronously and updates the
260
- * parent's value asynchonously via the `activeDateChange` event. The child component receives an
261
- * updated value asynchronously via the `activeCell` Input.
262
- */
263
- _updateActiveDate ( event : MatCalendarUserEvent < number > ) {
264
- const month = event . value ;
265
- const oldActiveDate = this . _activeDate ;
266
- this . activeDate = this . _getDateFromDayOfMonth ( month ) ;
267
-
268
- if ( this . _dateAdapter . compareDate ( oldActiveDate , this . activeDate ) ) {
269
- this . activeDateChange . emit ( this . _activeDate ) ;
270
- }
271
- }
272
-
273
255
/** Handles keydown events on the calendar body when calendar is in month view. */
274
256
_handleCalendarBodyKeydown ( event : KeyboardEvent ) : void {
275
257
// TODO(mmalerba): We currently allow keyboard navigation to disabled dates, but just prevent
@@ -345,10 +327,9 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
345
327
346
328
if ( this . _dateAdapter . compareDate ( oldActiveDate , this . activeDate ) ) {
347
329
this . activeDateChange . emit ( this . activeDate ) ;
348
-
349
- this . _focusActiveCellAfterViewChecked ( ) ;
350
330
}
351
331
332
+ this . _focusActiveCell ( ) ;
352
333
// Prevent unexpected default actions such as form submission.
353
334
event . preventDefault ( ) ;
354
335
}
@@ -395,11 +376,6 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
395
376
this . _matCalendarBody . _focusActiveCell ( movePreview ) ;
396
377
}
397
378
398
- /** Focuses the active cell after change detection has run and the microtask queue is empty. */
399
- _focusActiveCellAfterViewChecked ( ) {
400
- this . _matCalendarBody . _scheduleFocusActiveCellAfterViewChecked ( ) ;
401
- }
402
-
403
379
/** Called when the user has activated a new cell and the preview needs to be updated. */
404
380
_previewChanged ( { event, value : cell } : MatCalendarUserEvent < MatCalendarCell < D > | null > ) {
405
381
if ( this . _rangeStrategy ) {
@@ -422,18 +398,6 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
422
398
}
423
399
}
424
400
425
- /**
426
- * Takes a day of the month and returns a new date in the same month and year as the currently
427
- * active date. The returned date will have the same day of the month as the argument date.
428
- */
429
- private _getDateFromDayOfMonth ( dayOfMonth : number ) : D {
430
- return this . _dateAdapter . createDate (
431
- this . _dateAdapter . getYear ( this . activeDate ) ,
432
- this . _dateAdapter . getMonth ( this . activeDate ) ,
433
- dayOfMonth ,
434
- ) ;
435
- }
436
-
437
401
/** Initializes the weekdays. */
438
402
private _initWeekdays ( ) {
439
403
const firstDayOfWeek = this . _dateAdapter . getFirstDayOfWeek ( ) ;
0 commit comments