Skip to content

Value is not updated on DayPickerInput when value prop is in a different month #535

@supersime

Description

@supersime

There is a From and To DayPickerInput element on a page. Both have a value that comes from state.
When the From field is changed, an onDayChange function is used to update the value of the From and To dates in state.
However...
if the new From date is in a different month, then on the very first change of the From date the To date will not be updated.
There appears to be an issue in the DayPickerInput.js, componentWillReceiveProps function whereby this condition (if (hasDifferentValue && !shouldDisplayAnotherMonth)) is causing an issue. Based on my test scenario, hasDifferentValue is true, and shouldDisplayAnotherMonth is also true, and therefore there is no mapping of the nextProps to state - i.e. the state is not updated with the changed date.

Issue has been reproduced at:
https://codesandbox.io/s/yjo1nzx51z

Use the following steps to reproduce:
Scenario 1

  1. From and To dates default to 30-Oct-2017
  2. Change the From date to 15-Nov-17. Note the To date does not change. Expectation is this would have been updated to 15-Nov-17.
  3. Change the From date to 16-Nov-17. Note the To date does change. As expected.

Scenario 2 (NOTE: refresh the browser to start again):

  1. From and To dates default to 30-Oct-2017
  2. Change the From date to 31-Oct-2017. Note the To date does change. As expected.

Scenario 3 (NOTE: refresh the browser to start again):

  1. From and To dates default to 30-Oct-2017
  2. Click on the To date to note that the calendar is displayed in October.
  3. Change the From date to 15-Sep-2017. Note the To date does not change. Expectation is this would have been updated to 15-Sep-2017.
  4. Click on the To date to note that the calendar is displayed in September.
  5. Change the From date to 16-Sep-2017. Note the To date does change. As expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions