Repository: flatpickr/flatpickr (ts)

Issue:
jumpToDate() does not trigger any events
jumpToDate() does not trigger events like onMonthChange, onYearChange, or onChange. Not sure if it's intended to, but it's odd. 🤷‍♂️ 

https://codepen.io/tako1337/pen/VNzOrB

## Your Environment
flatpickr version used: 4.5.7
Browser name and version: Chrome 73
OS and version: Windows 10

Pull request:
Fixes #1746 - no events triggered by jumpToDate
- [x] Add the optional parameter
- [ ] Updated documentation to reflect new parameter

Patch:
diff --git a/src/index.ts b/src/index.ts
index 4d19c81c..d7d24e38 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -483,8 +483,9 @@ function FlatpickrInstance(
   /**
    * Set the calendar view to a particular date.
    * @param {Date} jumpDate the date to set the view to
+   * @param {boolean} triggerChange if change events should be triggered
    */
-  function jumpToDate(jumpDate?: DateOption) {
+  function jumpToDate(jumpDate?: DateOption, triggerChange?: boolean) {
     const jumpTo =
       jumpDate !== undefined
         ? self.parseDate(jumpDate)
@@ -495,6 +496,9 @@ function FlatpickrInstance(
             ? self.config.maxDate
             : self.now);
 
+    const oldYear = self.currentYear;
+    const oldMonth = self.currentMonth;
+
     try {
       if (jumpTo !== undefined) {
         self.currentYear = jumpTo.getFullYear();
@@ -506,6 +510,14 @@ function FlatpickrInstance(
       self.config.errorHandler(e);
     }
 
+    if (triggerChange && self.currentYear !== oldYear) {
+      triggerEvent("onYearChange");
+    }
+
+    if (triggerChange && (self.currentYear !== oldYear || self.currentMonth !== oldMonth)) {
+      triggerEvent("onMonthChange");
+    }
+
     self.redraw();
   }
 
diff --git a/src/types/instance.ts b/src/types/instance.ts
index d0cb0c1a..f584c7f5 100644
--- a/src/types/instance.ts
+++ b/src/types/instance.ts
@@ -95,7 +95,7 @@ export type Instance = Elements &
     close: () => void;
     destroy: () => void;
     isEnabled: (date: DateOption, timeless?: boolean) => boolean;
-    jumpToDate: (date?: DateOption) => void;
+    jumpToDate: (date?: DateOption, triggerChange?: boolean) => void;
     open: (e?: FocusEvent | MouseEvent, positionElement?: HTMLElement) => void;
     redraw: () => void;
     set: (


Test patch:
diff --git a/src/__tests__/index.spec.ts b/src/__tests__/index.spec.ts
index 70195ce1..92aecef9 100644
--- a/src/__tests__/index.spec.ts
+++ b/src/__tests__/index.spec.ts
@@ -730,6 +730,30 @@ describe("flatpickr", () => {
         expect(fp.currentYear).toEqual(2016);
       });
     });
+
+    it("triggers monthChange on jump", done => {
+      const fp = createInstance({
+        defaultDate: new Date(2019, 3, 17),
+        onMonthChange: () => {
+          expect(fp.currentMonth).toEqual(4);
+          done();
+        },
+      });
+
+      fp.jumpToDate(new Date(2019, 4, 17), true);
+    });
+
+    it("triggers yearChange on jump", done => {
+      const fp = createInstance({
+        defaultDate: new Date(2019, 3, 17),
+        onYearChange: () => {
+          expect(fp.currentYear).toEqual(2020);
+          done();
+        },
+      });
+
+      fp.jumpToDate(new Date(2020, 4, 17), true);
+    });
   });
 
   describe("UI", () => {