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

First date selection not clearable in selectRange mode #947

Open
2 tasks done
tayoawoyemi opened this issue Aug 7, 2024 · 3 comments
Open
2 tasks done

First date selection not clearable in selectRange mode #947

tayoawoyemi opened this issue Aug 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@tayoawoyemi
Copy link

Before you start - checklist

  • I followed instructions in documentation written for my React-Calendar version
  • I have checked if this bug is not already reported

Description

When using the calendar in range selection mode as a controlled component the first date selection of a range is currently not clearable.

Steps to reproduce

Example: https://codesandbox.io/p/sandbox/react-calendar-example-6gq3tr

  1. Go to the example codebox
  2. Select a date range
  3. Click the reset button
  4. See that both selected dates are reset
  5. Select a single date
  6. Click the reset button
  7. See that the selected date is not reset

Expected behavior

Setting the calendars value to null should reset a single date selection in selectRange mode

Actual behavior

Single date selection is not clearable while in selectRange mode

Additional information

Looks like this code is responsible:

https://github.com/wojtekmaj/react-calendar/blob/main/packages/react-calendar/src/Calendar.tsx#L692

// In the middle of range selection, use value from state if (selectRange && getIsSingleValue(valueState)) { return valueState; }

Environment

React-Calendar version: 5.0.0
React version: 18.0.2

@tayoawoyemi tayoawoyemi added the bug Something isn't working label Aug 7, 2024
@savayer
Copy link

savayer commented Aug 29, 2024

@tayoawoyemi have you found a way to solve this problem?

@savayer
Copy link

savayer commented Aug 29, 2024

only re-rendering helps me

<ReactCalendar
  key={rerenderKey}
  ...
/>

@tiagotwistag
Copy link

Same issue here, and ended up with the same solution of forcing a a re-mount of the component by changing the key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants