diff --git a/packages/react-day-picker/src/DayPicker.test.tsx b/packages/react-day-picker/src/DayPicker.test.tsx
index bc0359837..a77ca2020 100644
--- a/packages/react-day-picker/src/DayPicker.test.tsx
+++ b/packages/react-day-picker/src/DayPicker.test.tsx
@@ -533,6 +533,34 @@ describe("when the `month` is changed programmatically", () => {
});
});
+test("clamps the displayed month when endMonth changes before the current month", () => {
+ const { rerender } = render(
+ ,
+ );
+
+ expect(grid("September 2024")).toBeInTheDocument();
+
+ rerender(
+ ,
+ );
+
+ expect(grid("March 2024")).toBeInTheDocument();
+ expect(
+ screen.getByRole("combobox", { name: labelMonthDropdown() }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("combobox", { name: labelYearDropdown() }),
+ ).toBeInTheDocument();
+});
+
test("extends the default locale", () => {
render(
{
+ const constrainedMonth = getInitialMonth(
+ { month: firstMonth, numberOfMonths: props.numberOfMonths },
+ navStart,
+ navEnd,
+ dateLib,
+ );
+
+ if (!dateLib.isSameMonth(firstMonth, constrainedMonth)) {
+ setFirstMonth(constrainedMonth);
+ }
+ }, [
+ navEnd?.getTime(),
+ navStart?.getTime(),
+ props.numberOfMonths,
+ firstMonth.getTime(),
+ ]);
+
/** The months displayed in the calendar. */
// biome-ignore lint/correctness/useExhaustiveDependencies: We want to recompute only when specific props change.
const { months, weeks, days, previousMonth, nextMonth } = useMemo(() => {