Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
8.12k stars 2.24k forks source link

fix: "previous month" button appears when selecting a date #5214

Closed OlegDev1 closed 1 week ago

OlegDev1 commented 2 weeks ago

Description

Linked issue: #5193

Problem Even though the min date is provided, when selecting the second month, "previous month" button still appears. It shouldn't happen, because the calendar from the screenshots starts at November.

Changes Changed the calculation logic that determines whether previous month button should appear or not (borrowed some code from renderMonths, big thanks to @pmacmillan). Added a test case, in which a calendar is rendered with min date, after that the date from the second month is selected and it is expected for "previous month" button not to appear.

Screenshots

Calendar starts at November 7

Before image After image

Contribution checklist

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.89%. Comparing base (826ba90) to head (7069485). Report is 4 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #5214 +/- ## ======================================= Coverage 96.88% 96.89% ======================================= Files 29 29 Lines 3375 3381 +6 Branches 1409 1418 +9 ======================================= + Hits 3270 3276 +6 + Misses 105 103 -2 - Partials 0 2 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

OlegDev1 commented 2 weeks ago

Thank you very much for the review, I really appreciate it!

I have added an additional button check in the test case as Frank suggested. I also replaced the non-null assertion with an error check