Skip to content

fix(datetime): keep month when calendar is hidden - #31711

Open
officialasishkumar wants to merge 1 commit into
ionic-team:mainfrom
officialasishkumar:fix/datetime-hidden-calendar-month
Open

officialasishkumar wants to merge 1 commit into
ionic-team:mainfrom
officialasishkumar:fix/datetime-hidden-calendar-month

Conversation

@officialasishkumar

Copy link
Copy Markdown

Issue number: resolves #31416


What is the current behavior?

The calendar's scroll listener runs on a short debounce. If the month/year picker opens in that window, the listener runs while the calendar body is display: none. Every box then measures 0, which the listener reads as having scrolled to the previous month, so the month moves back by one.

What is the new behavior?

  • getChangedMonth returns early when the calendar body has no layout, so hiding and showing the grid leaves the month untouched.
  • Force-rendered months still go through. animateToDate waits on the listener to finish, so skipping them would leave forceRenderDate set and make every later scroll commit that stale date.
  • Added e2e tests covering both paths.

Does this introduce a breaking change?

  • Yes
  • No

Other information

This is the guard suggested in the issue and confirmed in the triage comment.

The tests dispatch the scroll event themselves, because the real timing is intermittent. I checked them against both failure modes in Chromium:

  • Without the fix, both new tests fail, with the month moving back (March 2026 instead of April 2026).
  • With an unconditional early return instead of the guard, the forceRenderDate test fails (April 2026 instead of June 2026).

With the fix, the tests pass in Chromium, Firefox and WebKit. So does a temporary test of the issue's real click sequence (month arrows, then the header straight away), which isn't part of this PR.

In a wider Chromium run of the datetime and datetime-button e2e suites with snapshots ignored, the only failures were outside this change. datetime/test/basic :818 has an un-awaited evaluate that fails with Test ended. datetime/test/custom :371 and datetime/test/values :46 failed once under load and passed 3 of 3 when rerun alone. I didn't compare snapshots.

Skip month detection in the calendar scroll listener when the calendar
body has no layout, which is the case while the month/year picker is
open or the host is hidden. Every box measures 0 then, which the
listener read as having scrolled to the previous month, so opening the
picker right after a scroll could move the month back.

Force-rendered months still go through, as animateToDate waits on the
listener to finish. Skipping them would leave forceRenderDate set and
make every later scroll commit that stale date.

closes ionic-team#31416
@officialasishkumar
officialasishkumar requested a review from a team as a code owner November 7, 2026 06:34
@vercel

vercel Bot commented Nov 7, 2026

Copy link
Copy Markdown

@officialasishkumar is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the package: core @ionic/core package label Nov 7, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ion-datetime walks workingParts back a month when the calendar body has no layout

1 participant