Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call onDayChange with undefined when day is not valid #647

Merged
merged 2 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/DayPickerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/daypickerinput/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<DayPickerInput onDayChange={onDayChange} />);
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(<DayPickerInput />);
Expand Down