Skip to content

Months are shown using a different layout after clearing dates in multi-month range selectionΒ #3960

@thepuzzlemaster

Description

@thepuzzlemaster

Describe the bug
I've noticed a strange behavior, which feels like a bug, but i may just be missing something. After clearing out a selected date range on the date-picker, the dates shown when opening the date-picker are different than the first time the date-picker was opened.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'docs page'
  2. Replace any of the examples with the sample code below
  3. Open the date-picker and choose any date range on the right-side calendar
  4. Clear the date range using the "X" button
  5. Open the date-picker again
() => {
  const [startDate, setStartDate] = useState(null);
  const [endDate, setEndDate] = useState(null);
  
  const onChange = React.useCallback((dates) => {
    setStartDate(dates[0]);
    setEndDate(dates[1]);
  }, [])
  return (
    <DatePicker
      endDate={endDate}
      isClearable
      minDate={new Date()}
      monthsShown={2}
      onChange={onChange}
      selected={startDate}
      selectsRange
      startDate={startDate}
    />
  );
};

Expected behavior
I don't expect the previous month to show up on the left side, since the entire month is disabled. I would expect that the first month to show up on the left, should be the current month. This is how the date-picker behaves on the first-render before clearing the dates

Actual behavior
The previous month shows up on the left side, even though all dates in that month are disabled. And additionally, this behavior is different from the first time the date-picker is opened, where the left-side month is the current month.

Screenshots
Initial render
image

After clearing the dates
image

Desktop (please complete the following information):

  • OS: osx
  • Browser: chrome
  • Version: whichever version is running on the docs page - I presume the latest. I am also seeing this in V4.8.0 locally

Additional context
I have tried adding showPreviousMonths={false} but it makes no difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions