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

When the date selection is canceled, the start month is set to last month. #5249

Open
miro-ring opened this issue Nov 28, 2024 · 4 comments
Open

Comments

@miro-ring
Copy link

miro-ring commented Nov 28, 2024

#3875

Same for this. Any solution??

@balajis-qb
Copy link

Hi @dongkyun-dev, I'll look into this issue.

@SaiBalaji202
Copy link

Hi,
Can you please explain a bit more on this issue? What's the expected behaviour and actual behaviour? Also if possible share the sample code that can reproduce the issue?

Currently I tried with the below code and it's working for me

() => {
  const [startDate, setStartDate] = useState(new Date());
  const [endDate, setEndDate] = useState(null);

  const handleChange = ([newStartDate, newEndDate]) => {
    setStartDate(newStartDate);
    setEndDate(newEndDate);
  };

  return (
    <DatePicker
    selectsRange
      startDate={startDate}
      endDate={endDate}
      dateFormat="MM/yyyy"
      onChange={handleChange}
      focusSelectedMonth={false}
      monthsShown={2}
      minDate={new Date()}
      shouldCloseOnSelect={false}
      isClearable
    />
  );
};

@miro-ring
Copy link
Author

miro-ring commented Dec 2, 2024

@SaiBalaji202
#3875
You can check expected behaviour in this link. If there’s anything else you need, please let me know by comment.

@balajis-qb
Thanks.

if (
this.state.monthSelectedIn !== undefined &&
prevProps.monthsShown !== this.props.monthsShown
) {
this.setState({ monthSelectedIn: 0 });
}

I can solve this issue by changing monthsShown temporary.

@SaiBalaji202
Copy link

SaiBalaji202 commented Dec 2, 2024

I couldn't get the actual issue described. Can you explain the issue once again with the expected and the actual behaviour? If you could share the sample code that reproduce the error, that would be even more helpful.

Are you saying the issue is with showPreviousMonths? As showPreviousMonths is disabled, we shouldn't show the last month of the current month? Currently for few cases, it's showing the previous months after clear, right?

For example

() => {
  const [startDate, setStartDate] = useState(null);
  return (
    <DatePicker
      showIcon
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      showPreviousMonths={false}
      monthsShown={2}
       minDate={new Date()}
       isClearable
    />
  );
};

In this code, if I select any date from the current month (December 2024), November is not showing after cleanup. But if I select any date from the right side month (January, 2025 in our case), & then clear the date, now when I reopen it's showing November 2024 and Dec 2024 (which is wrong) and we need to display Dec 2024 and Jan 2025. Am I understanding the issue correctly?

If my understanding is not correct, please share more details.

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

3 participants