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): RTL will no longer infinitely scroll #24475

Merged
merged 6 commits into from
Jan 4, 2022
Merged

Conversation

sean-perkins
Copy link
Contributor

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

The date picker will infinitely scroll on initialization when using RTL.

Issue Number: Resolves #24472

What is the new behavior?

The calculations for scroll positioning will account for RTL.

  • Fixes the next/previous icons to flip in RTL

Does this introduce a breaking change?

  • Yes
  • No

Other information

Before After
Kapture.2021-12-22.at.14.08.50.mp4
Kapture.2021-12-22.at.14.07.43.mp4

@@ -995,9 +997,12 @@ export class Datetime implements ComponentInterface {
const nextMonth = calendarBodyRef.querySelector('.calendar-month:last-of-type');
if (!nextMonth) { return; }

const isRTL = document.dir === 'rtl';
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to check if dir="rtl" was set on the host element as well. Might be good to make this a utility that other components can use as well. Doing a quick search reveals that other components do not check the host when they probably should: https://github.com/ionic-team/ionic-framework/search?l=TSX&p=2&q=rtl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a new util for isRTL.

How do you feel about splitting out a separate issue for each component that has rtl checks only for document? That way the change log will better reflect those changes to the util change and won't be tied to the datetime changes. If you feel good about that, I'm happy to create an issue for each.

Copy link
Contributor

@liamdebeasi liamdebeasi Jan 4, 2022

Choose a reason for hiding this comment

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

Yep let's log some tech debt for that 👍

@averyjohnston averyjohnston changed the title fix(datetime): RTL will no longer infinitily scroll fix(datetime): RTL will no longer infinitely scroll Jan 4, 2022
@averyjohnston
Copy link
Contributor

I'm still seeing the issue on Windows Chrome 🤔 Happens both when setting dir="rtl" on the <html>, or using ?rtl=true in the URL. I added console.log(isRTL(this.el)); at line 685 (right before setting scrollLeft and and ioCallback) and it's returning false for me.

@sean-perkins
Copy link
Contributor Author

I'm still seeing the issue on Windows Chrome 🤔 Happens both when setting dir="rtl" on the <html>, or using ?rtl=true in the URL. I added console.log(isRTL(this.el)); at line 685 (right before setting scrollLeft and and ioCallback) and it's returning false for me.

Ahh.. yeah I know the exact reason. The change to fix the lint error. One sec.

@sean-perkins
Copy link
Contributor Author

Fixed that issue & added a test to cover that condition.

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.

There we go, looking great now 👍

export const isRTL = (hostEl?: Pick<HTMLElement, 'dir'>) => {
if (hostEl) {
if (hostEl.dir !== '') {
return hostEl.dir.toLowerCase() === 'rtl';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be converting to lowercase? It looks "Ltr" should be treated as invalid looking at the accepted values: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to swap that to explicit checks. Was siding on Dx, but if the browser will ignore any values that aren't rtl | ltr | auto, that isn't very helpful to be different.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops I take it back. The browser dir is not case sensitive, so what you have currently aligns with how the browser behaves: https://codepen.io/liamdebeasi/pen/Jjrvgrp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, that change is reverted 👍

@sean-perkins sean-perkins merged commit 8f00008 into main Jan 4, 2022
@sean-perkins sean-perkins deleted the FW-444 branch January 4, 2022 21:15
@dviravr
Copy link

dviravr commented Jan 15, 2022

this isn't fix the problem for all cases.
if my app is in RTL mode, (on the 'ion-app') the infinity scroll is still appening.
in addition, the arrows, are still upside down

@zhuhuanzi
Copy link

@sean-perkins This problem still exists in Android 9. Android 12 is ok.

@zhuhuanzi
Copy link

@sean-珀金斯这个问题在Android 9中仍然存在。安卓12还可以。

"@ionic/angular": "^6.0.12"

@HamzaAdam
Copy link

HamzaAdam commented Jun 20, 2022

Image.from.iOS.mov

Still facing same issue in IOS. Is anyone know how to fix it?
Using direction attribute with ion-datetime component with presentation="date", dir="ltr", host direction is RTL.

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 scrolls infinitely with dir=rtl
6 participants