Skip to content
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

initialVisibleMonth ignored when startDate and endDate are set #148

Open
lsmilesbd opened this issue Mar 8, 2023 · 0 comments
Open

initialVisibleMonth ignored when startDate and endDate are set #148

lsmilesbd opened this issue Mar 8, 2023 · 0 comments

Comments

@lsmilesbd
Copy link

lsmilesbd commented Mar 8, 2023

@datepicker-react/hooks or @datepicker-react/styled version
e.g. @datepicker-react/[email protected]

Describe the bug
When passing in a startDate and endDate parameter to the in addition to a initialVisibleMonth useDatePicker hook, the initialVisibleMonth is ignored, and the the initialVisibleMonth defaults to the startDate

Source code (including props configuration)
Steps to reproduce the behavior:

const [state, setState] = useState({
    startDate: new Date(2020, 1, 1),
    endDate: new Date(2022, 1, 1),
    focusedInput: START_DATE
  });
  const {
    firstDayOfWeek,
    activeMonths,
    isDateSelected,
    isDateHovered,
    isFirstOrLastSelectedDate,
    isDateBlocked,
    isDateFocused,
    onDateHover,
    onDateSelect,
    onDateFocus,
    goToPreviousMonths,
    goToNextMonths
  } = useDatepicker({
    startDate: state.startDate,
    endDate: state.endDate,
    focusedInput: state.focusedInput,
    onDatesChange: handleDateChange,
    initialVisibleMonth: new Date(2022, 1, 1),
    numberOfMonths: 2
  });

  function handleDateChange(data) {
    if (!data.focusedInput) {
      setState({ ...data, focusedInput: START_DATE });
    } else {
      setState(data);
    }
  }

codeSandbox link

Screenshots/Gifs
If applicable, add screenshots or gifs to help explain your problem.
initialVisibleMonth param respected:
Screenshot 2023-03-08 at 15 55 52

initialVisibleMonth ignored, view is set to startDate:
Screenshot 2023-03-08 at 15 55 28

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Is the issue reproducible in Storybook?
Unknown - netlify link returns a 404

Additional context
Add any other context about the problem here.
It is an edge case where the datepicker is pre-filled with a range over 2 months.

I have been using this as a workaround

React.useEffect(() => goToDate(endDate, [goToDate]);

as a workaround to go to the current date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant