-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Popover: improve iframe offset computation #42417
Conversation
Size Change: +219 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
df90569
to
8140c3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shifting behavior could still be improved (as discussed in #42531 (comment)), as currently the popover's shift is limited in such a way that makes it stop right on top of a block when scrolling up:
Kapture.2022-07-22.at.12.33.16.mp4
We could either look into applying a fix to the "shift limiting" behavior separately (#42531), or we could try to add it to this PR. Any preferences?
I think it's ok to ship this separately as it wasn't intended as a fix for that, more a fix for the Link popovers that were all incorrectly positioned. |
37b11df
to
7967da9
Compare
I gave this PR another round of testing and found out another issue: the popover's offset doesn't seem to update after the block/pattern inserter is closed Kapture.2022-07-28.at.13.58.35.mp4I can't reproduce this issue in the post editor. |
This seems to be on trunk too. I'll test this now again, but I'd expect it's okay to merge and handle the other issues in follow ups. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me to land and iterate on the other issues. Thanks for your work and all the iterations! 💯
Thanks for the reviews and guidance, Nik and Marco! |
What?
#42389 fixed an issue with Link Control popovers going offscreen, but as @ntsekouras pointed out, in the site editor the popover isn't taking the iframe offset into account and while now onscreen is incorrectly positioned.
Why?
The issue seems to be that the custom
iframeOffset
middleware in the Popover component doesn't work well with floating-ui'sshift
middleware.shift
expects to receive any offsets via middleware data, butiframeOffset
doesn't do this:https://github.com/floating-ui/floating-ui/blob/77c4b27a8096cafe06e58b2c7592317d6d3a3aea/packages/core/src/middleware/shift.ts#L203-L212
The easiest fix seems to be use floating-ui's own
offset
middelware instead of our custom middleware.How?
In practice it was a bit harder than I thought to fix this. The main difficulty is that when using floating ui's
offset
middleware, themainAxis
andcrossAxis
values need to be specified instead ofx
andy
, and floating-ui doesn't seem to offer any way to determine what those are.It also seems that when position is
top
orleft
the offset needs to be subtracted, and whenbottom
orright
added. As soon as I fixed the link popover issue, the toolbar was offset incorrectly until I multiplied the offset by the correct sign.Testing Instructions
Expected: The toolbar and the link popover should be positioned correctly.
Screenshots or screencast
Before
After
Other screenshots
To make sure this was right, I tried setting the button block's popover positioning to 'top', 'bottom', 'left' and 'right' and checked the results. I also added some left margin to the site editor's iframe to ensure that x axis offsetting works correctly, and the results were all correct:
Top placement
Right placement
Bottom placement
Left placement