lanjingling0510 / react-mobile-datepicker

🙊 👻 look a demo, Please imitate mobile environment.
https://codepen.io/lanjingling0510/pen/LRpOYp?editors=1010
MIT License
301 stars 145 forks source link

reset the value to max or min if the current value is > max or < min #28

Closed magom001 closed 6 years ago

magom001 commented 6 years ago

We encountered an issue with the datepicker: if the user scrolls month and day of the month at the same time, it is possible to set the value of the datepicker outside the boundary of the min-max. In this case the whole datepicker becomes greyed out and unusable.

I added componentDidUpdate lifecycle hook that checks if the state.value is within min-max. If it is <min, set the value to min. If it >max, set the value to max.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.3%) to 92.727% when pulling 8b44a7d5a23ca8946c7fd2ce4fc281c448c9d19c on magom001:blocking_wheels_bug into 3f6ef0d3c726e462ad38790ea4b5046bc95cf8cd on lanjingling0510:master.

zengxiaoluan commented 6 years ago

@magom001 why you had modified so much code?

magom001 commented 6 years ago

@zengxiaoluan sorry about that: prettier formatted the code

lanjingling0510 commented 6 years ago

@magom001 I don't see what you've changed =。=. How do you feel about adding a lock? Just let a DatePickerItem scroll.

magom001 commented 6 years ago

I added:

componentDidUpdate() { const value = this.state.value; const { min, max } = this.props; if (value.getTime() > max.getTime()) { this.setState({ value: max }); }

It prevents the value to go outside of the min-max boundary

lanjingling0510 commented 6 years ago

@magom001 Has been updated to react-mobile-datepicker@3.0.12