-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
DayPicker resets to current month after date selection #2389
Comments
I have encountered this issue as well! |
It didn't work for me to revert the version. Could you take a look at my issue to see if you can help me? |
Reverting the version didn't help. The issue that I am facing is, I have the date picker placed inside a popover and on selecting the date from month other than the current, popover gets closed and reopening it, opens the date picker with the current date in focus. |
You can make an additional state for month navigation const [currentMonth, setCurrentMonth] = useState<Date | undefined>(new Date());
<DayPicker
...
month={currentMonth}
onMonthChange={setCurrentMonth}
/> |
As alternative It's possible to use const [selectedDate, setSelectedDate] = useState(new Date());
<Calendar
mode="single"
selected={selectedDate}
onSelect={setSelectedDate}
defaultMonth={selectedDate} // NOTE ME
/> So, if you are using |
const [currentMonth, setCurrentMonth] = useState<Date | undefined>(selectedDate || new Date());
<Calendar
mode="single"
selected={date}
month={currentMonth}
onMonthChange={setCurrentMonth}
onSelect={(dayDate: any) => {
setDate(dayDate);
if (setSelectedDate) {
setSelectedDate(dayDate);
}
}}
/> pls try this |
Hi, and thanks for reviewing this bug report! :)
Code
Expected Behavior
When a date is selected, the
DayPicker
should remain on the month of the selected date.Actual Behavior
In any selection mode (
single
,range
, ormultiple
), if you set astartMonth
orendMonth
and trigger anonSelect
that updates a React state, theDayPicker
display will reset to the current month instead of remaining on the month where you selected a day.Removing either
startMonth
andendMonth
oronSelect
resolves this issue.Exemple
CodeSandbox
The text was updated successfully, but these errors were encountered: