@@ -41,7 +41,7 @@ import rangePlugin from "flatpickr/dist/plugins/rangePlugin";
4141 [invalid]="invalid"
4242 [invalidText]="invalidText"
4343 [skeleton]="skeleton"
44- (valueChange)="onInputValueChange($event)">
44+ (valueChange)="onInputValueChange($event, 0 )">
4545 </ibm-date-picker-input>
4646 </div>
4747
@@ -57,7 +57,7 @@ import rangePlugin from "flatpickr/dist/plugins/rangePlugin";
5757 [invalid]="invalid"
5858 [invalidText]="invalidText"
5959 [skeleton]="skeleton"
60- (valueChange)="onInputValueRangeChange ($event)">
60+ (valueChange)="onInputValueChange ($event, 1 )">
6161 </ibm-date-picker-input>
6262 </div>
6363 </div>
@@ -91,7 +91,7 @@ export class DatePicker implements OnDestroy {
9191
9292 @Input ( ) id = `datepicker-${ DatePicker . datePickerCount ++ } ` ;
9393
94- @Input ( ) value : Array < any > ;
94+ @Input ( ) value : Array < any > = [ ] ;
9595
9696 @Input ( ) theme : "light" | "dark" = "dark" ;
9797
@@ -175,30 +175,18 @@ export class DatePicker implements OnDestroy {
175175 } ) ;
176176 }
177177
178- onInputValueChange ( event : string ) : void {
178+ onInputValueChange ( event : string , index : number ) : void {
179179 const eventDate = flatpickr . parseDate ( event , this . dateFormat , true ) ;
180- const previousDate = flatpickr . parseDate ( this . value [ 0 ] , this . dateFormat , true ) ;
180+ const previousDate = flatpickr . parseDate ( this . value [ index ] , this . dateFormat , true ) ;
181181 if ( eventDate ) {
182182 if ( ! previousDate || previousDate . getTime ( ) !== eventDate . getTime ( ) ) {
183- this . value = [ eventDate , this . value [ 1 ] ] ;
183+ this . value = [ ...this . value ] ;
184+ this . value [ index ] = eventDate ;
184185 }
185186 } else {
186187 if ( previousDate || event ) {
187- this . value = [ undefined , this . value [ 1 ] ] ;
188- }
189- }
190- }
191-
192- onInputValueRangeChange ( event : string ) : void {
193- const eventDate = flatpickr . parseDate ( event , this . dateFormat , true ) ;
194- const previousDate = flatpickr . parseDate ( this . value [ 1 ] , this . dateFormat , true ) ;
195- if ( eventDate ) {
196- if ( ! previousDate || previousDate . getTime ( ) !== eventDate . getTime ( ) ) {
197- this . value = [ this . value [ 0 ] , eventDate ] ;
198- }
199- } else {
200- if ( previousDate || event ) {
201- this . value = [ this . value [ 0 ] , undefined ] ;
188+ this . value = [ ...this . value ] ;
189+ this . value [ index ] = undefined ;
202190 }
203191 }
204192 }
0 commit comments