From 2704474f08f65b0cec079c2309d59299b91b0f82 Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Mon, 5 Mar 2018 10:10:21 +0100 Subject: [PATCH 1/2] Call `onDayChange` with `undefined` when day is not valid --- src/DayPickerInput.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/DayPickerInput.js b/src/DayPickerInput.js index 1f6d208de0..aaebeaae94 100644 --- a/src/DayPickerInput.js +++ b/src/DayPickerInput.js @@ -322,14 +322,13 @@ export default class DayPickerInput extends React.Component { const { value } = e.target; if (value.trim() === '') { this.setState({ value }); - if (onDayChange) { - onDayChange(undefined, {}); - } + if (onDayChange) onDayChange(undefined, {}); return; } const day = parseDate(value, format, dayPickerProps.locale); if (!day) { this.setState({ value }); + if (onDayChange) onDayChange(undefined, {}); return; } this.updateState(day, value); From a66eab24a985e981c5544ec5a93f82878c447146 Mon Sep 17 00:00:00 2001 From: Giampaolo Bellavite Date: Mon, 5 Mar 2018 10:14:57 +0100 Subject: [PATCH 2/2] Fix unit test --- test/daypickerinput/events.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/daypickerinput/events.js b/test/daypickerinput/events.js index 656836a1ec..9abf7c61d9 100644 --- a/test/daypickerinput/events.js +++ b/test/daypickerinput/events.js @@ -107,12 +107,12 @@ describe('DayPickerInput', () => { input.simulate('change', { target: { value: 'foo' } }); expect(wrapper.find('input')).toHaveProp('value', 'foo'); }); - it('should not call `onDayChange` if the value is not a valid date', () => { + it('should call `onDayChange` with `undefined` if the value is not a valid date', () => { const onDayChange = jest.fn(); const wrapper = mount(); const input = wrapper.find('input'); input.simulate('change', { target: { value: 'foo' } }); - expect(onDayChange).not.toHaveBeenCalled(); + expect(onDayChange).toHaveBeenCalledWith(undefined, {}); }); it("should update the input's value and the displayed month", () => { const wrapper = mount();