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 carousel sliding direction in RTL pages #33076

Closed
wants to merge 6 commits into from

Conversation

aqeelat
Copy link
Contributor

@aqeelat aqeelat commented Feb 13, 2021

Both LTR and RTL carousels slid in the same direction.

Fixed and tested.

@aqeelat aqeelat requested a review from a team as a code owner February 13, 2021 09:41
@ffoodd
Copy link
Member

ffoodd commented Feb 13, 2021

Could you provide a reduced test case please, or describe exactly what's wrong?

Because as of v5.0.0-beta2, they don't slide in the same direction:

Am I missing something?

@aqeelat
Copy link
Contributor Author

aqeelat commented Feb 13, 2021

When the slides are cycling, they both move in the same direction, which should not be the case.
This is what it looks like after the fix:
sliding direction

Before the fix, the RTL version would slide in the same way as the LTR.

@XhmikosR
Copy link
Member

We need tests, please add some tests.

@aqeelat
Copy link
Contributor Author

aqeelat commented Feb 14, 2021

I'm working on the tests but I'm having trouble coming up with a way to mock index.isRTL. Any suggestions?

2- made it so that rtl carousels can be used in ltl pages, by using a localized dir='rtl' tag. This could be replaced by a designated class.
@aqeelat
Copy link
Contributor Author

aqeelat commented Feb 15, 2021

Updated the pull request with unit tests.

Can you take a look at the added line in the constructor? I had to add it for testing, but I think it's helpful. I'm not sure if it's appropriate though. Maybe a class?

@XhmikosR @ffoodd

@ffoodd
Copy link
Member

ffoodd commented Feb 15, 2021

I'd stick with isRTL instead of adding it to the constructor—and for the least if you want to add it, this should be done in other components using it for consistency.

But JS is not my specialty. @rohit2sharma95 any opinion on this?

// | F | T | Option 1 |
// | F | F | Option 2 |
// +-------+------------------------------+----------+
const directionalClassName = this.isRTL === (direction === DIRECTION_NEXT) ? CLASS_NAME_END : CLASS_NAME_START
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I like these, I feel like it's less readable...

@@ -120,6 +120,7 @@ class Carousel extends BaseComponent {
this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0
this._pointerEvent = Boolean(window.PointerEvent)

this.isRTL = this._element.dir === 'rtl' || isRTL
Copy link
Member

Choose a reason for hiding this comment

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

Why is the new check needed? Or why doesn't the previous one suffice?

BTW, I have a draft PR around to switch isRTL to a function so that it's tree-shaken, but I doubt it's related.

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 had to add it so that I can produce the unit tests I was asked for. Then I realized it might be helpful in some cases.

isRTL only checks if the tag has dir=rtl attribute. This means that you can't have an RTL carousel otherwise. One use case: in the documentation for bootstrap itself on how to make a page rtl. The page itself could be in English, but the carousel could be in Arabic.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we support such a case in v5 @ffoodd ?

Copy link
Collaborator

@rohit2sharma95 rohit2sharma95 Feb 16, 2021

Choose a reason for hiding this comment

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

Yes, that case is not supported yet. And this check is then redundant 🙂

Copy link
Member

Choose a reason for hiding this comment

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

@aqeelat: I merged #32446. Your use case makes sense, but I thought it wasn't supported.

That being said, it seems it's sort of supported https://getbootstrap.com/docs/5.0/getting-started/rtl/#ltr-and-rtl-at-the-same-time, so after #32913 or in #32913, we could refactor the isRTL function to check for an element's direction and or document.documentElement.dir.

We just need to make sure we have JS tests to cover these changes

@XhmikosR
Copy link
Member

We also have #32913 FYI

@XhmikosR
Copy link
Member

@rohit2sharma95 @ffoodd I think that #32913 is better to understand and it should have the same fix. Please have a look there and let's close this one.

@aqeelat thanks for the PR, regardless :)

@XhmikosR
Copy link
Member

Closing in favor of #32913. We can revisit later if needed.

@XhmikosR XhmikosR closed this Feb 16, 2021
@rohit2sharma95
Copy link
Collaborator

I'd stick with isRTL instead of adding it to the constructor

I am personally in favor of #32446 so that dir can be checked in run time. @ffoodd

@ffoodd ffoodd mentioned this pull request Feb 16, 2021
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants