Skip to content

Commit

Permalink
fix(date-picker): manage to reselect date while closing calendar (#2845)
Browse files Browse the repository at this point in the history
Co-authored-by: Akshat Patel <[email protected]>
  • Loading branch information
kush-savani and Akshat55 authored Apr 4, 2024
1 parent 17289f5 commit 73a2ed9
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/datepicker/datepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,11 @@ export class DatePicker implements
// This makes sure that the `flatpickrInstance selectedDates` are in sync with the values of
// the inputs when the calendar closes.
if (this.range && this.flatpickrInstance) {
if (this.flatpickrInstance.selectedDates.length !== 2) {
// we could `this.flatpickrInstance.clear()` but it insists on opening the second picker
// in some cases, so instead we do this
this.setDateValues([]);
this.doSelect([]);
return;
}
const inputValue = this.input.input.nativeElement.value;
const rangeInputValue = this.rangeInput.input.nativeElement.value;
if (inputValue || rangeInputValue) {
const parseDate = (date: string) => this.flatpickrInstance.parseDate(date, this.dateFormat);
this.setDateValues([parseDate(inputValue), parseDate(rangeInputValue)]);
this.setDateValues([parseDate(inputValue), parseDate(rangeInputValue || inputValue)]);
this.doSelect(this.flatpickrInstance.selectedDates);
}
}
Expand Down

0 comments on commit 73a2ed9

Please sign in to comment.