MCPcopy Create free account
hub / github.com/angular/components / ngOnChanges

Method ngOnChanges

src/material/datepicker/calendar.ts:455–497  ·  view source on GitHub ↗
(changes: SimpleChanges<this>)

Source from the content-addressed store, hash-verified

453 }
454
455 ngOnChanges(changes: SimpleChanges<this>) {
456 // Ignore date changes that are at a different time on the same day. This fixes issues where
457 // the calendar re-renders when there is no meaningful change to [minDate] or [maxDate]
458 // (#24435).
459 const minDateChange: SimpleChange | undefined =
460 changes['minDate'] &&
461 !this._dateAdapter.sameDate(
462 changes['minDate'].previousValue as D | null,
463 changes['minDate'].currentValue as D | null,
464 )
465 ? changes['minDate']
466 : undefined;
467 const maxDateChange: SimpleChange | undefined =
468 changes['maxDate'] &&
469 !this._dateAdapter.sameDate(
470 changes['maxDate'].previousValue as D | null,
471 changes['maxDate'].currentValue as D | null,
472 )
473 ? changes['maxDate']
474 : undefined;
475
476 const changeRequiringRerender = minDateChange || maxDateChange || changes['dateFilter'];
477
478 if (changeRequiringRerender && !changeRequiringRerender.firstChange) {
479 const view = this._getCurrentViewComponent();
480
481 if (view) {
482 // Schedule focus to be moved to the active date since re-rendering can blur the active
483 // cell (see #29265), however don't do so if focus is outside of the calendar, because it
484 // can steal away the user's attention (see #30635).
485 if (this._elementRef.nativeElement.contains(_getFocusedElementPierceShadowDom())) {
486 this._moveFocusOnNextTick = true;
487 }
488
489 // We need to `detectChanges` manually here, because the `minDate`, `maxDate` etc. are
490 // passed down to the view via data bindings which won't be up-to-date when we call `_init`.
491 this._changeDetectorRef.detectChanges();
492 view._init();
493 }
494 }
495
496 this.stateChanges.next();
497 }
498
499 /** Focuses the active date. */
500 focusActiveCell() {

Callers

nothing calls this directly

Calls 4

_initMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected