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

Handle position when used in RTL content is way off (landscape only) #101

Closed
moloko opened this issue Dec 13, 2022 · 6 comments
Closed

Handle position when used in RTL content is way off (landscape only) #101

moloko opened this issue Dec 13, 2022 · 6 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation has workaround Issue has a viable workaround
Milestone

Comments

@moloko
Copy link

moloko commented Dec 13, 2022

In landscape mode, something goes very wrong with the handle display when this is used in a web page (or element) that has dir="rtl" set on on it... it seems to be displaying on the far right of the .handle-container div.

I've set up a demo here: https://codesandbox.io/s/react-compare-slider-simple-example-forked-u6wlmp

From what I can see if you remove position:absolute from the div that's the immediate child of it, that fixes it:
image

@moloko
Copy link
Author

moloko commented Dec 13, 2022

I'm not sure whether when being used in 'RTL mode' a user would expect the handle to slide in the opposite direction... but that's a whole other question!

@nerdyman
Copy link
Owner

nerdyman commented Dec 13, 2022

Hey Matt, that's crazy bug! I'll see if I can figure out why it's happening.

The position: absolute is needed on the inner child to ensure the handle only uses up its intrinsic width so interactive elements like Google maps can be used without being obstructued by the handle. The inner child element has been removed in v3 though so it might be solved when that gets published this happens in v3 too. I'll take a look for a fix with v2 too since v3 probably won't be released until early next year.

Good question on whether a RTL user would expect the slide direction to be reversed. I'd assume they'd still want it to slide as it does in LTR mode but not sure. Also not sure if the arrows should be reversed within the slider button.

If you're not using interactive content in the slider you could force the styles for now:

https://codesandbox.io/s/react-compare-slider-simple-example-forked-7ylclj?file=/src/styles.css

html[dir="rtl"] [data-rcs="handle-container"] > div {
  position: static !important;
}

@nerdyman nerdyman added the bug Something isn't working label Dec 13, 2022
@nerdyman
Copy link
Owner

nerdyman commented Dec 13, 2022

This happens on v3 too. As a workaround there's the CSS hack above, or you could adddir="ltr" on the slider component itself.

I've updated the demo to toggle the dir prop https://codesandbox.io/s/react-compare-slider-simple-example-forked-7ylclj?file=/src/App.jsx:545-579

I hadn't considered how RTL affects things so think it needs more thought in general. Maybe the rendering of itemOne and itemTwo should be reversed too?

@nerdyman nerdyman added the has workaround Issue has a viable workaround label Dec 13, 2022
@moloko
Copy link
Author

moloko commented Dec 14, 2022

or you could adddir="ltr" on the slider component itself.

Of course! Why didn't I think of that... 🤦‍♂️

@moloko
Copy link
Author

moloko commented Dec 14, 2022

I hadn't considered how RTL affects things so think it needs more thought in general. Maybe the rendering of itemOne and itemTwo should be reversed too?

I honestly don't know for sure, I've not seen anything like this component done for RTL before!

But, as I understand it, the general rule for bidirectional content is that everything should be 'mirrored' bar a few exceptions like media playback controls and the playback progress indicator (as apparently these refer to the direction of 'the video tape' not of time)... so given that I'd say it seems like that you would reverse the rendering and handle drag initial position/drag direction in landscape mode.

@nerdyman nerdyman modified the milestones: v3, v3.x Jan 18, 2023
@nerdyman nerdyman modified the milestones: v3.x, v3 Jan 31, 2023
@nerdyman nerdyman added the documentation Improvements or additions to documentation label Apr 3, 2023
@nerdyman
Copy link
Owner

This has been fixed in v3!

npm install react-compare-slider@latest
yarn add react-compare-slider@latest
pnpm install react-compare-slider@latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation has workaround Issue has a viable workaround
Projects
No open projects
Development

No branches or pull requests

2 participants