@@ -157,6 +157,9 @@ interface VisibleCalendar {
157157 ]
158158} )
159159export class DaterangepickerComponent implements OnInit , OnChanges {
160+ @Input ( )
161+ initialDates : [ string | Dayjs , string | Dayjs ] = null ;
162+
160163 @Input ( )
161164 startDate = dayjs ( ) . utc ( true ) . startOf ( 'day' ) ;
162165
@@ -413,9 +416,28 @@ export class DaterangepickerComponent implements OnInit, OnChanges {
413416 }
414417 }
415418 this . locale . daysOfWeek = daysOfWeek ;
419+
420+ // Initialize with initialDates if provided
421+ let leftMonth : Dayjs ;
422+ let rightMonth : Dayjs ;
423+
424+ if ( this . initialDates && this . initialDates . length === 2 ) {
425+ leftMonth = dayjs . isDayjs ( this . initialDates [ 0 ] ) ? this . initialDates [ 0 ] . clone ( ) : dayjs ( this . initialDates [ 0 ] ) . utc ( true ) ;
426+ rightMonth = dayjs . isDayjs ( this . initialDates [ 1 ] ) ? this . initialDates [ 1 ] . clone ( ) : dayjs ( this . initialDates [ 1 ] ) . utc ( true ) ;
427+ } else {
428+ leftMonth = dayjs ( ) . utc ( true ) ;
429+ rightMonth = leftMonth . clone ( ) . add ( 1 , 'month' ) ;
430+ }
431+
432+ // Set calendar view without selecting dates
433+ if ( ! this . startDate || this . startDate . isSame ( dayjs ( ) . utc ( true ) . startOf ( 'day' ) ) ) {
434+ this . leftCalendar . month = leftMonth . clone ( ) ;
435+ this . rightCalendar . month = rightMonth . clone ( ) ;
436+ }
437+
416438 if ( this . inline ) {
417- this . cachedVersion . start = this . startDate . clone ( ) ;
418- this . cachedVersion . end = this . endDate . clone ( ) ;
439+ this . cachedVersion . start = this . startDate ? .clone ( ) ;
440+ this . cachedVersion . end = this . endDate ? .clone ( ) ;
419441 }
420442
421443 if ( this . startDate && this . timePicker ) {
@@ -1455,7 +1477,7 @@ export class DaterangepickerComponent implements OnInit, OnChanges {
14551477 const minute = parseInt ( String ( this . timepickerVariables [ side ] . selectedMinute ) , 10 ) ;
14561478 const second = this . timePickerSeconds ? parseInt ( String ( this . timepickerVariables [ side ] . selectedSecond ) , 10 ) : 0 ;
14571479 return date . clone ( ) . hour ( hour ) . minute ( minute ) . second ( second ) ;
1458-
1480+
14591481 } else {
14601482 return ;
14611483 }
0 commit comments