Skip to content
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

[Range Calendar] Update left/right side calendar months when programmatically setting the time #643

Open
BionBit opened this issue Dec 2, 2019 · 1 comment

Comments

@BionBit
Copy link

BionBit commented Dec 2, 2019

Consider that clients might add a functionality to programmatically set the time (like our project does).
e.g. buttons like 'Last Month', 'Last Week'.

Clicking those buttons to update the selectedValue sent as prop to RangeCalendar will not work as expected.

STR:

  1. Select the current date in the first week of the left-side calendar (like Dec 2nd).

  2. Left-side calendar shows Dec 2019, right side calendar shows Jan 2020

  3. Click the 'Last Month' (an example) to update the selectedValue sent as prop to RangeCalendar

  4. Notice that the calendars do not update

  • Current behavior: left side calendar shows Dec 2019, right side calendar shows Jan 2020
  • Expected behavior: left side calendar shows Nov 2019, right side calendar shows Dec 2019

Proposed fix in 'RangeCalendar.js', tested locally,

  static getDerivedStateFromProps(nextProps, state) {
    const newState = {};
    - if ('value' in nextProps) {
    + if ((nextProps.selectedValue[0] && nextProps.selectedValue[1]) || 'value' in nextProps) {
      newState.value = normalizeAnchor(nextProps, 0);
    }
@zhaoyao91
Copy link

zhaoyao91 commented Dec 17, 2019

I encountered the same problem.

A workaround here: add a timestamp as the key of the calendar, and refresh it on any user events. Thus the calendar will get recreate and show the correct display.

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

No branches or pull requests

2 participants