react-calendar icon indicating copy to clipboard operation
react-calendar copied to clipboard

Double view calendar switches activeStartDate to the next month when the date is selected on the right

Open majsterkoo opened this issue 4 years ago • 14 comments

Hi, I'm using ReactCalendar in uncontrolled mode. How I can prevent calendar to switch to next month if click on date on right side in showDoubleView? When on left is June, on right July, then after select some date in July calendar render July in left side and next month is showed in right side.

//fetchWeeks - function to call api request for other component
<ReactCalendar showWeekNumbers showDoubleView onChange={fetchWeeks} defaultValue={today} />

Thanks for help/advice.

majsterkoo avatar Mar 17 '20 14:03 majsterkoo

The UX experience is being affected by this issue (there should be a way to disable it).

carlosbensant avatar Apr 27 '20 17:04 carlosbensant

Hi

Has someone found a workaround to disable this behavior please ? Or Can the author provide a props to disable it please ?

Thx a lot

Best regards

lauterry avatar Jan 26 '21 13:01 lauterry

I think this behaviour should be configurable. However, I think what it really needs is an animation to show the transition to the user. Right now it's really difficult for the user to see what is going on.

leolozes avatar Jan 26 '21 15:01 leolozes

I have just opened an issue to request an animation to show the transition to the user

https://github.com/wojtekmaj/react-calendar/issues/483

lauterry avatar Feb 07 '21 16:02 lauterry

If you look at this issue, OP seems to have run into a similar problem. He hacked together a solution by changing the activeStartDate prop through the onActiveStartDateChange and onChange handler.

Digging through the react-calendar code, the problem while in double view is that the onChange handler in Calendar.jsx sets an activeStartDate each time, which is why clicking on the next month teleports you there.

onChange = (value, event) => { 
... 
this.setStateAndCallCallbacks({	    
      activeStartDate: nextActiveStartDate,
      value: nextValue,
    });
}

A possible solution would be to add a showDoubleView condition that only sets activeStartDate: nextActiveStartDate when you are in a single month view.

ernie-h avatar Feb 12 '21 00:02 ernie-h

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

github-actions[bot] avatar Nov 01 '21 00:11 github-actions[bot]

This issue was closed because it has been stalled for 14 days with no activity.

github-actions[bot] avatar Nov 22 '21 00:11 github-actions[bot]

Edit: nevermind, we implemented our own calendar.

Any updates on this? The issue has been closed, but the UX is still quite bad, and a lot of users don't understand what is going on and end up selecting a much bigger range than intended.

A quick demo to see the effect and understand the problem. The user doesn't move his cursor, but is automatically positioned in the next month:

chrome-capture

leolozes avatar Dec 03 '21 12:12 leolozes

any update to this?

swee76 avatar Oct 23 '22 14:10 swee76

@wojtekmaj How to make the calendar keep on the same side when click on the value which is in right side? I wanted to create a calendar which is important to filter past 3 months of data. So basically current month should be on right side, instead of left side.. Whatever that, when click on the any date which is in right side calendar month moves to the left side, please could you fix this?

swee76 avatar Oct 31 '22 10:10 swee76

Hello

Please re consider fixing this issue please ?

Thank you.

lauterry avatar Jan 23 '23 16:01 lauterry

Great calendar, just how to disable this moving the month to the left, after clicking on the value located on the right.

Nmkop1 avatar Jan 26 '23 10:01 Nmkop1

Same problem here.

Any updates ?

MarcosMoraes23 avatar Apr 07 '23 18:04 MarcosMoraes23

Solution I used, seems to work fine for me. Maybe It's useful to someone else too:

Make activeStartDate controlled:

const [activeStartDate, setActiveStartDate] = useState(new Date());

Set following props on Calendar component:

goToRangeStartOnSelect={false}
activeStartDate={activeStartDate}

On activeStartDate do following so that onChange event doesn't trigger activeStartDate change:

onActiveStartDateChange={(data) => {
    if (data.action !== "onChange") {
        setActiveStartDate(data.activeStartDate);
    }
}}

svekko avatar Jun 06 '23 05:06 svekko