Skip to content

Commit

Permalink
fix(limel-date-picker): change picker value when changing the input
Browse files Browse the repository at this point in the history
fix #297
  • Loading branch information
BregenzerK authored and adrianschmidt committed Sep 10, 2019
1 parent 1dc84c4 commit 7105483
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/components/date-picker/pickers/MonthPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions src/components/date-picker/pickers/Picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions src/components/date-picker/pickers/QuarterPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/components/date-picker/pickers/YearPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down

0 comments on commit 7105483

Please sign in to comment.