Repository: gpbl/react-day-picker (ts)

Issue:
Selecting day on calendar with DayPickerInput and format=Array throws error
Selecting day in overlay calendar while using DayPickerInput with format=Array<string> throws error "Uncaught TypeError: format.match is not a function" from moment.js.

Traced this to moment.js parsing accepting an array of string formats to check against but moment.format() expects a single string as argument [[doc]](https://momentjs.com/docs/#/displaying/format/)

Example:
https://codesandbox.io/s/5wz092n1pk

Maybe as an easy compromise/fix when format is given as an array default to formatting by the first array element?

Pull request description:
Use first element `format` (fix #491)

Patch:
diff --git a/src/DayPickerInput.js b/src/DayPickerInput.js
index 3073bd9d1..9527c839a 100644
--- a/src/DayPickerInput.js
+++ b/src/DayPickerInput.js
@@ -261,13 +261,20 @@ export default class DayPickerInput extends React.Component {
       return;
     }
 
+    const { format } = this.props;
     const m = moment(day);
-    this.setState({ value: m.format(this.props.format), month: day }, () => {
-      if (this.props.onDayChange) {
-        this.props.onDayChange(m, modifiers);
+    this.setState(
+      {
+        value: m.format(typeof format === 'string' ? format : format[0]),
+        month: day,
+      },
+      () => {
+        if (this.props.onDayChange) {
+          this.props.onDayChange(m, modifiers);
+        }
+        this.hideAfterDayClick();
       }
-      this.hideAfterDayClick();
-    });
+    );
   };
 
   renderOverlay() {


Test patch:
diff --git a/test/daypickerinput/events.js b/test/daypickerinput/events.js
index 758cee4dd..9bb4ccfb9 100644
--- a/test/daypickerinput/events.js
+++ b/test/daypickerinput/events.js
@@ -191,6 +191,24 @@ describe('DayPickerInput', () => {
         expect(onDayChange.mock.calls[0][0].format('L')).toBe('02/08/2017');
         expect(onDayChange.mock.calls[0][1]).toEqual({ foo: true });
       });
+      it('should work also when `format` is an array', () => {
+        const onDayChange = jest.fn();
+        const wrapper = mount(
+          <DayPickerInput
+            onDayChange={onDayChange}
+            format={['L', 'LL']}
+            dayPickerProps={{
+              month: new Date(2017, 1),
+            }}
+          />
+        );
+        wrapper.instance().showDayPicker();
+        wrapper
+          .find('.DayPicker-Day')
+          .at(10)
+          .simulate('click');
+        expect(onDayChange.mock.calls[0][0].format('L')).toBe('02/08/2017');
+      });
       it('should hide the day picker when clicking on a day', done => {
         const wrapper = mount(<DayPickerInput />);
         wrapper.instance().showDayPicker();