Skip to content

Commit 4aa5535

Browse files
andrewseguinjosephperrott
authored andcommitted
fix(calendar): should markForCheck when properties are changed (#15102)
* fix(calendar): should markForCheck when properties are changed * fix test
1 parent 230b1ed commit 4aa5535

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/lib/datepicker/calendar.spec.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,13 @@ describe('MatCalendar', () => {
188188
});
189189

190190
it('should move focus to the active cell when the view changes', () => {
191+
calendarInstance.currentView = 'multi-year';
192+
fixture.detectChanges();
193+
191194
const activeCell =
192195
calendarBodyEl.querySelector('.mat-calendar-body-active')! as HTMLElement;
193-
194196
spyOn(activeCell, 'focus').and.callThrough();
195-
fixture.detectChanges();
196-
zone.simulateZoneExit();
197-
198-
expect(activeCell.focus).not.toHaveBeenCalled();
199197

200-
calendarInstance.currentView = 'multi-year';
201-
fixture.detectChanges();
202198
zone.simulateZoneExit();
203199

204200
expect(activeCell.focus).toHaveBeenCalled();

src/lib/datepicker/calendar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes
262262
set activeDate(value: D) {
263263
this._clampedActiveDate = this._dateAdapter.clampDate(value, this.minDate, this.maxDate);
264264
this.stateChanges.next();
265+
this._changeDetectorRef.markForCheck();
265266
}
266267
private _clampedActiveDate: D;
267268

@@ -270,6 +271,7 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes
270271
set currentView(value: MatCalendarView) {
271272
this._currentView = value;
272273
this._moveFocusOnNextTick = true;
274+
this._changeDetectorRef.markForCheck();
273275
}
274276
private _currentView: MatCalendarView;
275277

0 commit comments

Comments
 (0)