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

fix(datetime): changing months work if partially visible #27917

Merged
merged 4 commits into from
Aug 4, 2023
Merged

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Aug 2, 2023

Issue number: resolves #27913


What is the current behavior?

When determining what the changed month is, we grab the element at the center of the datetime and then grab the nearest calendar month. This works fine if the datetime is fully in view, but if the center point is out of the viewport then this will return null. As a result, scrolling in the datetime will break.

What is the new behavior?

  • We now check scroll position instead of querying for DOM elements at coordinates. This allows the view to continue to update even if the entire calendar body is outside the viewport.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 7.2.2-dev.11690996559.1019674a

@stackblitz
Copy link

stackblitz bot commented Aug 2, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the package: core @ionic/core package label Aug 2, 2023
@liamdebeasi liamdebeasi marked this pull request as ready for review August 2, 2023 14:52
@liamdebeasi
Copy link
Contributor Author

Found an edge case. Moving back to draft for now.

@liamdebeasi liamdebeasi marked this pull request as draft August 2, 2023 15:29
const monthColumnItems = page.locator('ion-datetime .month-column .picker-item:not(.picker-item-empty)');
const ionChange = await page.spyOnEvent('ionChange');
Copy link
Contributor Author

@liamdebeasi liamdebeasi Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test started to flake after my changes. This test touches the wheel picker which does not use any of the changed code. I noticed that the test was not waiting for .datetime-ready and it was not waiting for the ionChange event, so it's possible that my change made datetime slightly faster/slower such that this test is now consistently failing.

I simplified the test but made sure to check the same datetime APIs, so this behavior is definitely still working.

await monthColumn.locator('.picker-item[data-value="10"]').click();
await page.waitForChanges();

await yearColumn.locator('.picker-item[data-value="2021"]').click();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ended up being redundant because clicking "October" automatically switched the year to "2021"


await yearColumn.locator('.picker-item[data-value="2021"]').click();
await page.waitForChanges();
await ionChange.next();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test also started to fail only in Firefox. The problem was that tapping the "October" button started to scroll, but we closed the month/year picker before the scroll finished so the value was never updated. By waiting for ionChange we can ensure the value is updated.

@liamdebeasi liamdebeasi marked this pull request as ready for review August 2, 2023 19:19
Copy link
Contributor

@averyjohnston averyjohnston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, this should make things way more efficient. Just had one quick question about a test but otherwise LGTM.

@liamdebeasi liamdebeasi added this pull request to the merge queue Aug 4, 2023
Merged via the queue into main with commit eb19c28 Aug 4, 2023
45 checks passed
@liamdebeasi liamdebeasi deleted the FW-4871 branch August 4, 2023 19:00
@Et3rnal
Copy link

Et3rnal commented Sep 13, 2023

Will this fix make it to version 6?
Is there a work around the issue?
I'm only experiencing the issue when using Edge!
I'm ionic/angular 6.1.11

Thanks

@liamdebeasi
Copy link
Contributor Author

No, this fix is only for Ionic 7. We are not actively developing Ionic 6 anymore.

github-merge-queue bot pushed a commit that referenced this pull request Apr 29, 2024
Issue number: resolves #29198

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

In #27917 I failed to
account for RTL. This caused the navigation with the arrow buttons to
break because the scroll position was always < 2.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Datetime now checks if the component is in RTL mode when creating the
scrollLeft threshold.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
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: ios, next and prev buttons do not work when calendar grid is only partially visible
4 participants