-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
base: master
Are you sure you want to change the base?
fix: check on wrong value in RangePicker
onSubmit
#679
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
src/RangePicker.tsx
Outdated
@@ -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] || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!selectedValue[index] || | |
!selectedValue?.[index] || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some test case to cover it. |
… disabledDate to start date
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([]); | ||
}); |
There was a problem hiding this comment.
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.
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 passundefined
to -disabledDate
function.