tailwind-datepicker-react icon indicating copy to clipboard operation
tailwind-datepicker-react copied to clipboard

fix: you should not be able to go further than the last date

Open pmaidens opened this issue 1 year ago • 1 comments

What does this change do?

If the developer has specified a minDate and the user arrives at the last possible page but continues to hit the previous button, the date will continue to be modified and will therefore put them in a "negative" state, so that when they hit the next button, the calendar does not move to the next month.

The same is true for a maxDate and the next button.

This change fixes it so that continuing to push the previous button will not put the user into a "negative" state.

Why was this happening?

The date being passed into the goToPrevNext function is a reference to the state of the calendar. Since it is only a reference, when we add time to it, it is actually mutating the state in a way that is invisible to react. This causes the date to change without calling the setState function and without changing the reference. Not only is changing the state at this moment not wanted, but React is also unaware of the change and does not know to rerender.

To fix this, we need to clone the date so that the state's version is not being mutated.

pmaidens avatar Dec 02 '23 03:12 pmaidens

@OMikkel can you take a look at this?

pmaidens avatar Feb 27 '24 05:02 pmaidens