File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
projects/igniteui-angular/src/lib/calendar Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments