diff --git a/src/DayPickerInput.js b/src/DayPickerInput.js index 3073bd9d1d..9527c839ab 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() { diff --git a/test/daypickerinput/events.js b/test/daypickerinput/events.js index 758cee4dda..9bb4ccfb91 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( + + ); + 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(); wrapper.instance().showDayPicker();