react-date-picker icon indicating copy to clipboard operation
react-date-picker copied to clipboard

Calendar popup state is not reset when the Date Value is set based on state change

Open iamanoopmk opened this issue 1 year ago • 13 comments

Before you start - checklist

  • [X] I followed instructions in documentation written for my React-Date-Picker version
  • [X] I have checked if this bug is not already reported

Description

When using the library and I change the date value from external action, the value shown in the text box updates correctly. But the calendar that pops up is still on the old year and month.

I have a basic example setup in the below codesandbox https://codesandbox.io/s/react-date-picker-xxsgjk

Steps to reproduce

Steps to reproduce using the below codesandbox

  1. Open the calendar and choose a date from previous year (June 1st, 2023)
  2. Click the button to reset the date
  3. Verify date is set to Jan 1st, 2024
  4. Click on the calendar icon and the calendar still shows the old June month from 2023 while expectation is the it should open Jan 2024.

Expected behavior

The calendar should open to the same month and year as displayed in the text box

Actual behavior

The calendar opens to the previously selected month and year that was set by actually clicking on the calendar

Additional information

No response

Environment

  • Browser (if applicable): ALL
  • React-Date-Picker version: ALL
  • React version: ALL

iamanoopmk avatar Jul 16 '24 07:07 iamanoopmk

Could anyone provide an input here? If this is the expected behaviour then that can be mentioned and the bug report can be closed.

iamanoopmk avatar Aug 21 '24 04:08 iamanoopmk

Any update on this issue?

Purgenta avatar Aug 29 '24 15:08 Purgenta

I just ran into this issue too. Sometimes it's possible to work around it by using a key depending on the use case, but that wouldn't work well for the "reset" button example above.

grovesNL avatar Nov 06 '24 14:11 grovesNL

I just ran into this issue too. Sometimes it's possible to work around it by using a key depending on the use case, but that wouldn't work well for the "reset" button example above.

Yeah that is exactly how i worked around this issue although I'd prefer to avoid remounting the component itself tbh as you get the "flashy" effect.

Purgenta avatar Nov 06 '24 14:11 Purgenta

Sorry, I am a bit confused. Could you elaborate on this workaround please?

iamanoopmk avatar Nov 06 '24 14:11 iamanoopmk

Use the date you have currently set as a key for the DatePicker itself

Purgenta avatar Nov 06 '24 14:11 Purgenta

I just want to add that setting the key based on the selected value works fine but please don't make the same mistake I made at first.

You should set the key of the calendar via calendarProps and not directly in the root props of the date picker, something like: <DatePicker {...datePickerProps} calendarProps={{ key: selectedValue?.toString() }} />

This way only the calendar will get re-rendered, which is what we want in this scenario, instead of re-rendering the whole date picker.

lopesmartinz avatar Dec 03 '24 16:12 lopesmartinz

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

github-actions[bot] avatar Mar 10 '25 00:03 github-actions[bot]

Still an issue

grovesNL avatar Mar 14 '25 00:03 grovesNL

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

github-actions[bot] avatar Jun 16 '25 00:06 github-actions[bot]

Still an issue

grovesNL avatar Jun 16 '25 00:06 grovesNL

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

github-actions[bot] avatar Sep 22 '25 00:09 github-actions[bot]

Still an issue

grovesNL avatar Sep 22 '25 01:09 grovesNL