Skip to content

DayPicker resets to current month after date selection #2389

@DarXnake

Description

@DarXnake

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions