Skip to content

fix: check on wrong value in RangePicker onSubmit#679

Open
AmyHuang82 wants to merge 3 commits intoreact-component:masterfrom
AmyHuang82:fix/on-submit-selected-value-could-be-empty-array
Open

fix: check on wrong value in RangePicker onSubmit#679
AmyHuang82 wants to merge 3 commits intoreact-component:masterfrom
AmyHuang82:fix/on-submit-selected-value-could-be-empty-array

Conversation

@AmyHuang82
Copy link
Copy Markdown

@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
Copy Markdown

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

Comment thread src/RangePicker.tsx Outdated
if (
// When user typing disabledDate with keyboard and enter, this value will be empty
!selectedValue ||
!selectedValue[index] ||
Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

@yoyo837
Copy link
Copy Markdown
Member

yoyo837 commented Oct 6, 2023

Please add some test case to cover it.

Comment thread tests/keyboard.spec.tsx
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
Copy Markdown
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