udecode / plate

A rich-text editor powered by AI
https://platejs.org
Other
12.18k stars 742 forks source link

Floating toolbar button will move with scroll #3157

Closed felixfeng33 closed 1 month ago

felixfeng33 commented 7 months ago

Description

If the editor has a fixed height, the floating toolbar will be strange.

https://github.com/udecode/plate/assets/164472012/bc5b2c04-9bbd-472d-aa78-9717d15ebfa9

Steps to Reproduce

Sandbox

Expected Behavior

Environment

Bounty

Click here to add a bounty via Algora.

Funding

Fund with Polar

georeith commented 4 months ago

This issue is because of wrapping the floating toolbar in <PortalBody /> it moves the element which is passed to @floating-ui's setFloatingRef outside of the scroll hierarchy:

https://github.com/udecode/plate/blob/889b58ce09c93c78da9c104d5617887f4842698a/apps/www/src/registry/default/plate-ui/floating-toolbar.tsx#L56

The simple fix for me was to not use <PortalBody />. If you do portal the item into the body then it will also lag behind when you scroll instead of scroll smoothly with your content. This is because onScroll does not trigger at the same rate the page actually scrolls and the updates are slow. Removing <PortalBody /> also fixes this because the element is scrolled with its container smoothly by the browser before @floating-ui's updates its position.

zbeyens commented 1 month ago

Fixed by removing PortalBody