-
-
Notifications
You must be signed in to change notification settings - Fork 84
Fix: trigger month change when pressing the arrows in the calendar #201
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
base: main
Are you sure you want to change the base?
Fix: trigger month change when pressing the arrows in the calendar #201
Conversation
Thank you @Maxime-BARRY-SQLI, we need this fix! |
Hello @farhoudshapouran, are you ok to merge this PR ? |
Thanks for the PR! The month navigation detection is working well. I was wondering if we could also trigger the onYearChange callback when navigating between months that span different years? For example, when going from December 2023 to January 2024, or from January 2024 to December 2023. Currently, the onChangeMonth function only calls onMonthChange, but it might be useful to also check if the year has changed and trigger onYearChange accordingly. Here's a suggestion: const onChangeMonth = useCallback(
(value: number) => {
const currentDate = stateRef.current.currentDate;
const newDate = dayjs(currentDate).add(value, 'month');
const currentYear = dayjs(currentDate).year();
const newYear = dayjs(newDate).year();
if (currentYear !== newYear) {
onYearChange(newYear);
}
onMonthChange(newDate.month());
dispatch({
type: CalendarActionKind.CHANGE_CURRENT_DATE,
payload: dayjs(newDate),
});
},
[stateRef, dispatch, onMonthChange, onYearChange]
); This would ensure that both onMonthChange and onYearChange are properly triggered when navigating between months that span different years. What do you think? @Maxime-BARRY-SQLI |
Hello @SWARVY, thanks for your suggestion. I've pushed a new commit that allows onSelectYear to be triggered when the user switches from December to January (or vice versa). If you think there are any new things I can improve, please let me know. 👍 |
@farhoudshapouran this feels like a necessary adjustment of the onMonthChange function. Can you please review and merge this PR? |
Issue #195
Trigger
onMonthChange
callback when user change month from the arrows in the calendar display