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

onActiveStartDateChange not fired when navigating to the first period in a view #970

Open
2 tasks done
will-hart opened this issue Jan 23, 2025 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working

Comments

@will-hart
Copy link

will-hart commented Jan 23, 2025

Before you start - checklist

  • I followed instructions in documentation written for my React-Calendar version
  • I have checked if this bug is not already reported

Description

The onActiveStartDateChange is not fired when drilling down to the first period from any view. For instance

  • going from decade to the first year, or
  • from a year to the first month

Steps to reproduce

Add an onActiveStartDateChange handler which logs the args.

Expected behavior

onActiveStartDateChange is fired when drilling down from and to any level, regardless of which month is selected.

Actual behavior

onActiveStartDateChange is not fired when drilling down to the first period. See:

Image

Additional information

Note: This is related to #458, but that issue only refers to navigating to January from the year view.

Looking at the code I think the main issues is the check here for areDatesEqual because if I understand it navigating to the year view sets the active date to January 1st.

Maybe I'm missing the complexity here, but could this not be resolved by changing the line from

if (onActiveStartDateChange && !areDatesEqual(activeStartDate, nextActiveStartDate)) {

to something naive like:

const drillingDown = action === 'drillDown' && activeStartDate.getMonth() === 0
if (onActiveStartDateChange && (!areDatesEqual(activeStartDate, nextActiveStartDate) || drillingDown)) {

I think this would only capture the instances where it doesn't currently fire, but I'm not familiar enough with the code base to be sure. Are there circumstances where it wouldn't be appropriate to fire the event when drilling down to January?

Actually on reflection you may also need to check for drillUp when January is selected and you drill up the event won't currently fire, but it will if you're in February for the first drillUp but not subsequent ones.

Environment

  • Browser (if applicable): firefox latest stable
  • React-Calendar version: "react-calendar": "^5.1.0"
  • React version: "react": "^18"
@will-hart will-hart added the bug Something isn't working label Jan 23, 2025
@will-hart
Copy link
Author

The workaround is to duplicate the onActiveStartDateChange handler in onDrillDown, via something like:

onDrillDown={(options) => {
  if (options.activeStartDate?.getMonth() !== 0) {
  	return;
  }

  // otherwise call the same handler
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant