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

fix: check on wrong value in RangePicker onSubmit #679

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
onSubmit: () => {
if (
// When user typing disabledDate with keyboard and enter, this value will be empty
!selectedValue ||
!selectedValue?.[index] ||
// Normal disabled check
(disabledDate && disabledDate(selectedValue[index]))
) {
Expand Down
21 changes: 21 additions & 0 deletions tests/keyboard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,25 @@ describe('Picker.Keyboard', () => {
expect(isSame(onSelect.mock.calls[0][0], '1990-12-03')).toBeTruthy();
});
});

it('range picker value should be empty array when typing invalid or disabledDate to start date', () => {
const onCalendarChange = jest.fn();
const now = new Date();
const { container } = render(
<MomentRangePicker
onCalendarChange={onCalendarChange}
disabledDate={(date) => date.month() < now.getMonth()}
/>,
);

openPicker(container);
fireEvent.change(container.querySelector('input'), { target: { value: '1990-1-1' } });
closePicker(container);
expect(onCalendarChange.mock.calls).toEqual([]);

openPicker(container);
fireEvent.change(container.querySelector('input'), { target: { value: '2000-01-01' } });
closePicker(container);
expect(onCalendarChange.mock.calls).toEqual([]);
});
Comment on lines +590 to +609
Copy link
Author

@AmyHuang82 AmyHuang82 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if is the right place or the right way for the cover test. Any suggestions are welcome.

});