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

showPreviousMonths={true} is not working properly #4023

Closed
gianpierobenvenuto opened this issue May 13, 2023 · 5 comments
Closed

showPreviousMonths={true} is not working properly #4023

gianpierobenvenuto opened this issue May 13, 2023 · 5 comments

Comments

@gianpierobenvenuto
Copy link

You can see this issue in action on the "Show previous month" example found on the demo website https://reactdatepicker.com/

What happens?

If you have showPreviousMonths={true} and you click any day it will jump to the previous month instead. This also applies to different cases such as implementations with selectsRange={true} and monthsShown={2}.

@Kenan-Kuzgun
Copy link

daterangepicker-issue

<DatePicker
ref={datepickerRef}
locale="tr"
dateFormat="dd MMMM yyyy"
selectsRange={true}
showPreviousMonths={true}
monthsShown={2}
onChange={(update) => {
setDateRange(update);
}}
customInput={}
startDate={startDate}
endDate={endDate}
maxDate={maxDate}
minDate={minDate}
onApply={(start, end) => {
setStartDate(start);
setEndDate(end);
}}
>

 Same issue ! 

@Burak-Ozlece
Copy link

same issue too

@comountainclimber
Copy link

Any update on this? Its super broken

@Kenan-Kuzgun
Copy link

No, we couldn't fix it.

@comountainclimber
Copy link

comountainclimber commented Sep 7, 2023

Ok I actually was able to hack my way around this issue with something like the following:

const START_OF_LAST_MONTH = startOfMonth(subMonths(new Date(), 1));
const [startDate, setStartDate] = useState(START_OF_LAST_MONTH);
const [initialized, setInitialized] = useState(false);
useEffect(
  function clearPreviousMonthStartDate() {
    if (!initialized) {
      setStartDate(null);
      setInitialized(true);
    }
    return function resetInitializedState() {
      setInitialized(false);
    };
  },
  [startDate, initialized]
);

return (
  <DatePicker
    fixedHeight
    open
    onChange={([start, end]) => {
      setStartDate(start);
      setEndDate(end);
    }}
    monthsShown={2}
    inline
    selectsRange
    startDate={startDate}
    endDate={endDate}
    maxDate={maximumDate}
    minDate={minimumDate}
    renderDayContents={renderCustomDayContents}
    disabledKeyboardNavigation
  />
);

This will render the picker with the visual appearance of what showPreviousMonths prop provides

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

4 participants