gpbl / react-day-picker

DayPicker is a customizable date picker component for React. Add date pickers, calendars, and date inputs to your web applications.

Home Page:https://daypicker.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: DayPicker does not automatically navigate to selected date

tyforcode opened this issue · comments

Bug description

Thanks for the library! I found an issue where if you set the selected value of the <DayPicker> component with something like an initial state, the component will not show the selected date in the UI. Instead, it will default to the earliest date in the range.

To reproduce

https://codesandbox.io/p/sandbox/react-daypicker-forked-4n69dz

Steps

  1. Step an initial Date state
  2. Set the following props on the DayPicker component
        fromDate={new Date("10/10/2020")}
        toDate={new Date("02/02/2022")}
        captionLayout="dropdown"
  1. Observe the component or refresh the sample to demonstrate the bug

Expected behavior

Ideally, the DayPicker component would show the selected value by default when it's set by an outside state.

Screenshots

n/a

Additional context

My specific use case is around a combination of fromDate, toDate and captionLayout where the year does not change correctly. However, this is also applicable to the base DayPicker component.