diff --git a/src/components/date-picker/pickers/MonthPicker.tsx b/src/components/date-picker/pickers/MonthPicker.tsx index cdf3da928d..0c4a71fab9 100644 --- a/src/components/date-picker/pickers/MonthPicker.tsx +++ b/src/components/date-picker/pickers/MonthPicker.tsx @@ -45,6 +45,11 @@ export class MonthPicker extends Picker { protected handleClose(selectedDates) { super.handleClose(selectedDates); + this.selectMonth( + this.flatpickr.selectedDates, + this.flatpickr.input.value, + this.flatpickr + ); this.flatpickr.prevMonthNav.removeEventListener( 'mousedown', this.prevYear diff --git a/src/components/date-picker/pickers/Picker.ts b/src/components/date-picker/pickers/Picker.ts index d7ffe58d42..508bbd3125 100644 --- a/src/components/date-picker/pickers/Picker.ts +++ b/src/components/date-picker/pickers/Picker.ts @@ -73,10 +73,23 @@ export abstract class Picker { } protected handleClose(selectedDates) { - const date = selectedDates[0] + const momentInputDate = moment( + this.flatpickr.input.value, + this.dateFormat + ); + let pickerDate = selectedDates[0] ? new Date(selectedDates[0].toJSON()) : null; - this.change.emit(date); + const isSameInput = momentInputDate.isSame(moment(pickerDate)); + if (!isSameInput) { + if (momentInputDate.isValid()) { + pickerDate = momentInputDate.toDate(); + this.flatpickr.setDate(pickerDate); + } else { + this.flatpickr.clear(); + } + } + this.change.emit(pickerDate); } private getMomentLang() { diff --git a/src/components/date-picker/pickers/QuarterPicker.tsx b/src/components/date-picker/pickers/QuarterPicker.tsx index 55524eb092..1a77221e8c 100644 --- a/src/components/date-picker/pickers/QuarterPicker.tsx +++ b/src/components/date-picker/pickers/QuarterPicker.tsx @@ -46,6 +46,11 @@ export class QuarterPicker extends Picker { protected handleClose(selectedDates) { super.handleClose(selectedDates); + this.selectQuarter( + this.flatpickr.selectedDates, + this.flatpickr.input.value, + this.flatpickr + ); this.flatpickr.prevMonthNav.removeEventListener( 'mousedown', this.prevYear diff --git a/src/components/date-picker/pickers/YearPicker.tsx b/src/components/date-picker/pickers/YearPicker.tsx index 4b2fa9ec64..08458590a9 100644 --- a/src/components/date-picker/pickers/YearPicker.tsx +++ b/src/components/date-picker/pickers/YearPicker.tsx @@ -18,6 +18,7 @@ export class YearPicker extends Picker { ) { super(dateFormat, language, change); this.handleChange = this.handleChange.bind(this); + this.handleClose = this.handleClose.bind(this); this.handleReady = this.handleReady.bind(this); } @@ -36,6 +37,14 @@ export class YearPicker extends Picker { this.selectYear(selectedDates, dateString); } + protected handleClose(selectedDates) { + super.handleClose(selectedDates); + this.selectYear( + this.flatpickr.selectedDates, + this.flatpickr.input.value + ); + } + private handleReady(_, __, fp) { this.bootstrapYearPicker(fp); const inputValue = fp.input.value;