Skip to content

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