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

Conversation

AmyHuang82
Copy link

@AmyHuang82 AmyHuang82 commented Sep 26, 2023

In RangePicker selectedValue will be an array.
So when user typing invalid or disabled start date this !selectedValue equals to ![] will be false, and then pass undefined to -disabledDate function.

@vercel
Copy link

vercel bot commented Sep 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
picker ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 11:57am

@@ -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] ||
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
!selectedValue[index] ||
!selectedValue?.[index] ||

Copy link
Author

Choose a reason for hiding this comment

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

@yoyo837
Copy link
Member

yoyo837 commented Oct 6, 2023

Please add some test case to cover it.

Comment on lines +590 to +609
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([]);
});
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants