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

Tooltip position not working correctly with RTL #2104

Closed
ShahriarKh opened this issue Aug 13, 2022 · 8 comments
Closed

Tooltip position not working correctly with RTL #2104

ShahriarKh opened this issue Aug 13, 2022 · 8 comments
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@ShahriarKh
Copy link

What package has an issue

@mantine/core

Describe the bug

The position of tooltip is incorrect in RTL mode. For example, choosing "Right" in RTL renders the tooltip on the left side.

LTR (correct)

image

RTL (incorrect)

image

What version of @mantine/hooks page do you have in package.json?

5.1.5

If possible, please include a link to a codesandbox with the reproduced problem

No response

Do you know how to fix the issue

No

Are you willing to participate in fixing this issue and create a pull request with the fix

Yes

Possible fix

I need to take a look at the source code.

@ShahriarKh ShahriarKh changed the title Tooltip Arrow not working correctly with RTL Tooltip position not working correctly with RTL Aug 13, 2022
@ShahriarKh
Copy link
Author

ShahriarKh commented Aug 13, 2022

Just took a quick look at source code. I think this line is causing the problem (since it's using theme.dir):

const tooltip = useTooltip({
position: getFloatingPosition(theme.dir, position),

And this is the getFloatingPosition that swaps right and left based on theme direction!

import type { FloatingPosition, FloatingSide, FloatingPlacement } from '../types';
export function getFloatingPosition(
dir: 'rtl' | 'ltr',
position: FloatingPosition
): FloatingPosition {
if (dir === 'rtl' && (position.includes('right') || position.includes('left'))) {
const [side, placement] = position.split('-') as [FloatingSide, FloatingPlacement];
const flippedPosition = side === 'right' ? 'left' : 'right';
return placement === undefined ? flippedPosition : `${flippedPosition}-${placement}`;
}
return position;
}

@ShahriarKh
Copy link
Author

ShahriarKh commented Aug 13, 2022

I'm taking a look at other components and will update the list of affected components below:

  • Tooltip
  • Menu (Arrow rotation is also incorrect)
  • Drawer

I believe there should be an option (global or per component) to let develops decide if they want to swap positions based on dir or not, because when you are working on a multilingual app/website, it makes sense to swap positions based on the direction; this way, the layout and components automatically adapt to the direction, but when you are working on a RTL-only app/website, it makes the maintenance hard because of inverted positions.

@rtivital
Copy link
Member

Flipping position is the correct logic – if you are building website that uses both rtl and ltr, you would want those positions flipped. The prop on theme to configure this behavior will be nice though. The arrow position is not correct, it should be fixed.

@ShahriarKh
Copy link
Author

I see... so, how can I contribute to add that prop?

@rtivital
Copy link
Member

Yes, sure, feel free to send a PR, if you can also fix the arrow position for rtl that would be great

@ShahriarKh
Copy link
Author

Okay, I will take a look at the code and see what I can do!

@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Aug 18, 2022
@rtivital
Copy link
Member

Fixed in 5.1.7

@ShaMan123
Copy link

ShaMan123 commented Jun 21, 2023

This position is not fixed, the tip is fixed

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

3 participants