Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pmaidens
Copy link

@pmaidens pmaidens commented Dec 2, 2023

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
Copy link
Author

@OMikkel can you take a look at this?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants