Hi, and thanks for reviewing this bug report! :)
Code
import { useState } from "react";
import { DayPicker, DateRange } from "react-day-picker";
import "react-day-picker/style.css";
export default function App() {
const [selectedPeriod, setSelectedPeriod] = useState<DateRange | undefined>();
return (
<DayPicker
mode="range"
startMonth={new Date("2024-07-01")}
endMonth={new Date("2025-07-31")}
onSelect={setSelectedPeriod}
/>
);
}
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, or multiple), if you set a startMonth or endMonth and trigger an onSelect that updates a React state, the DayPicker display will reset to the current month instead of remaining on the month where you selected a day.
Removing either startMonth and endMonth or onSelect resolves this issue.
Exemple
CodeSandbox
Hi, and thanks for reviewing this bug report! :)
Code
Expected Behavior
When a date is selected, the
DayPickershould remain on the month of the selected date.Actual Behavior
In any selection mode (
single,range, ormultiple), if you set astartMonthorendMonthand trigger anonSelectthat updates a React state, theDayPickerdisplay will reset to the current month instead of remaining on the month where you selected a day.Removing either
startMonthandendMonthoronSelectresolves this issue.Exemple
CodeSandbox