Skip to content

Commit 8d5ca57

Browse files
committed
fix(calendar): show right month when value is set for 9.1.x #8173
1 parent d5dfa28 commit 8d5ca57

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

projects/igniteui-angular/src/lib/calendar/calendar-base.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,16 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
150150
*/
151151
public set value(value: Date | Date[]) {
152152
if (!value || !!value && (value as Date[]).length === 0) {
153+
this.selectedDatesWithoutFocus = new Date();
153154
return;
154155
}
155-
156+
if (!this.selectedDatesWithoutFocus) {
157+
const valueDate = value[0] ? Math.min.apply(null, value) : value;
158+
const date = this.getDateOnly(new Date(valueDate)).setDate(1);
159+
this.viewDate = new Date(date);
160+
}
156161
this.selectDate(value);
162+
this.selectedDatesWithoutFocus = value;
157163
}
158164

159165
/**
@@ -345,6 +351,11 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
345351
*/
346352
public selectedDates;
347353

354+
/**
355+
* @hidden
356+
*/
357+
private selectedDatesWithoutFocus;
358+
348359
/**
349360
* @hidden
350361
*/

projects/igniteui-angular/src/lib/calendar/calendar.component.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,22 @@ describe('IgxCalendar - ', () => {
289289
expect(bodyMonth.nativeElement.textContent.trim()).toMatch('8');
290290
});
291291

292+
it('Should show right month when value is set', () => {
293+
expect(calendar.weekStart).toEqual(WEEKDAYS.SUNDAY);
294+
expect(calendar.selection).toEqual('single');
295+
296+
const date = new Date(2020, 8, 28);
297+
calendar.value = date;
298+
fixture.detectChanges();
299+
expect(
300+
(fixture.componentInstance.model as Date).toDateString()
301+
).toMatch(date.toDateString());
302+
expect((calendar.value as Date).toDateString()).toMatch(
303+
date.toDateString()
304+
);
305+
expect(calendar.viewDate.getMonth()).toEqual(date.getMonth());
306+
});
307+
292308
it('Should properly set locale', () => {
293309
fixture.componentInstance.viewDate = new Date(2018, 8, 17);
294310
fixture.componentInstance.model = new Date();

0 commit comments

Comments
 (0)