Hacker0x01 / react-datepicker

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

Wrong year is shown in year select if past date is selected with minDate={new Date()} #4849

Open parvesh2810 opened 1 month ago

parvesh2810 commented 1 month ago

Describe the bug Wrong year is shown in year select dropdown if past date is selected with minDate={new Date()}

Sample Code

() => { const [startDate, setStartDate] = useState('10/18/2023'); return ( <DatePicker showMonthDropdown showYearDropdown dropdownMode='select' minDate={new Date()} selected={startDate} onChange={(date) => setStartDate(date)} /> ); };

Screenshot

Screenshot 2024-05-31 at 5 03 08 PM

Macbook Air M1 Brave Browser

asada-no4 commented 3 days ago

Hi, parvesh2810. I don't think it is a good idea to activate the year 2023 in the year selection dropdown in the above state. It is not correct to make selected date to prior to minDate (a date that cannot be selected), so you need to re-select 2024 or later in the year selection dropdown. (I have a feeling the current behavior is correct)

Sorry if this is not what you intended.