Skip to content

fix: position of side menu controllers in rtl - #922

Open
zaaakher wants to merge 1 commit into
TypeCellOS:mainfrom
zaaakher:fix/rtl-side-menu
Open

zaaakher wants to merge 1 commit into
TypeCellOS:mainfrom
zaaakher:fix/rtl-side-menu

Conversation

@zaaakher

Copy link
Copy Markdown
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

@vercel

vercel Bot commented Jul 14, 2024 •

Copy link
Copy Markdown

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

@vercel

vercel Bot commented Jul 14, 2024

Copy link
Copy Markdown

@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
Copy Markdown
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?

@YousefED YousefED left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(see comment above)

@zaaakher

zaaakher commented Jul 17, 2024 •

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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

zaaakher commented Jul 17, 2024 •

Copy link
Copy Markdown
Contributor Author

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. 😅

@MashdorDev

Copy link
Copy Markdown

Another RTL case, from La Suite Docs (suitenumerique/docs#2919), which sets dir="auto" on block content. What only BlockNote can fix:

  • the side menu stays on the left of RTL blocks (this PR)
  • nested blocks use margin-left, so an RTL child and grandchild share the right edge
  • a table follows its first cell's direction
  • align right is justify-content: flex-end, the left edge in RTL
  • left is the default alignment and renders no attribute, so align left can't be set on an RTL block

Logical properties (margin-inline-start, inset-inline-start) would cover most of it.

This branch was successfully deployed

1 active deployment
Preview – blocknote — 3ab38759 Deployed Jul 14, 2024 by vercel[bot]
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.

4 participants