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: position of side menu controllers in rtl #922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zaaakher
Copy link
Contributor

This PR simply makes the side menu buttons to be in the correct position when layout is RTL.

Before

blocknote_rtl_before

After

blocknote_rtl_after

Copy link

vercel bot commented Jul 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview Jul 14, 2024 4:02am

Copy link

vercel bot commented Jul 14, 2024

@zaaakher is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@YousefED
Copy link
Collaborator

Thanks for your PR @zaaakher.

I'm curious about the root cause of this. If you set dir="rtl" on the html or container, I would expet Floating UI to automatically flip directions.

According to the docs: (https://floating-ui.com/docs/usefloating#placement)

The -start and -end alignments are
logical
and will adapt to the writing direction (e.g. RTL) as expected.

Could it be the root cause of this issue is somewhere else?

Copy link
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

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

(see comment above)

@zaaakher
Copy link
Contributor Author

zaaakher commented Jul 17, 2024

@YousefED you're right, it should ideally adapt to RTL without explicit dir prop or any prop-drilling.

After a little digging, it seems that the floatingStyles coming from the useFloating hook is the one preventing -start from being dynamic with the layout direction.

When I comment out this line

The -start positioning works fine (but the fixed/absolute positioning breaks)

blocknote_rtl_floating

@zaaakher
Copy link
Contributor Author

Digging into the source-code of floating-ui, I think this is the root cause of the issue:
https://github.com/floating-ui/floating-ui/blob/cea9065811ff347cfe388720b3cc91165c8cebe7/packages/react-dom/src/useFloating.ts#L159

I think it should be inset-inline-start

zaaakher added a commit to zaaakher/floating-ui that referenced this pull request Jul 17, 2024
Currently `floatingStyles` returned from `useFloating` is overwriting placement styles and preventing `-start` to truly adapt to RTL layouts.

See TypeCellOS/BlockNote#922 (comment)
@zaaakher
Copy link
Contributor Author

zaaakher commented Jul 17, 2024

It seems that floatingStyles.transform is the one positioning it and not left/insetInlineStart as I thought.

Based on the response from floating-ui here floating-ui/floating-ui#2982 (comment) it seems the expected automatic direction flip based on dir layout isn't yet supported natively in floating-ui.

Other than the minor prop-drilling suggested in this PR, I can't honestly think of an alternative way to do it. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants