wojtekmaj / react-calendar

Ultimate calendar for your React app.
https://projects.wojtekmaj.pl/react-calendar
MIT License
3.52k stars 509 forks source link

Setting the value of the calendar to undefined doesn't deselect the day that was previously selected #921

Closed santiagopuentep closed 3 months ago

santiagopuentep commented 7 months ago

Before you start - checklist

Description

I set the value to a certain date and that day turns blue. If I then set the value back to undefined, the day is still blue.

Steps to reproduce

  1. Set the value prop to a day.
  2. Set the value prop to undefined.
  3. See how the day that was set in step 1 is still blue.

Expected behavior

The blue color should disappear if no date is selected.

Actual behavior

The blue color is still there as if there was a date selected, but the value is undefined so there shouldn't be any.

Additional information

No response

Environment

rlebascle commented 7 months ago

@santiagopuentep If you set the value to null it will work as expected.

santiagopuentep commented 7 months ago

@santiagopuentep If you set the value to null it will work as expected.

It worked. Thanks! It still looks like a bug so I'll leave the issue opened.

jul0706 commented 7 months ago

It doesen't work for me. In mode allowPartialRange=true, if selected just a begin of date ranges, when I want clear values, I get setValues(null), but the blue color is still there. If selected both of values date range, clearing (setValues(null)) is working. React-Calendar version: 4.8.0 React version: 18.2.0

rlebascle commented 7 months ago

@jul0706 Yes, I have met that bug too. But it doesn't seem to be related to allowPartialRange=true, it also happen with selectRange only. I did investigate and it seems to come from that line: https://github.com/wojtekmaj/react-calendar/blob/v3.0.0/src/Calendar.jsx#L176 I didn't manage to fix it. From what I understand the Calendar is holding a "state" value internally.

rlebascle commented 7 months ago

I made a code sandbox to reproduce the bug. Code sanbox

github-actions[bot] commented 4 months ago

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] commented 3 months ago

This issue was closed because it has been stalled for 14 days with no activity.

Travis-Kirton commented 1 month ago

This is still an issue, I'm able to workaround by setting a key prop on the calendar but that feels dirty. Any scope to pick this up and fix? Or I can take a look at some point.