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

Site editor: fix padding and margin visualizer positioning #43971

Merged

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Sep 8, 2022

What?

Fixes #41823

TLDR - Ensures frameOffset is not applied for popovers that render inline in the site editor's iframe.

Longer explanation:
The site editor has its content within an iframe, and usually most popovers (like the block toolbar) render in the main document. An x/y offset needs to be applied to these popovers so that they're in the correct position on the screen.

There are two situations where this offset doesn't need to be applied. If the popover and its anchor/reference are both not in the iframe (for example, a popover for the block inspector). Or if the popover and its anchor/reference are both in the iframe. The latter is the situation for the padding margin visualizers—they need to be rendered in the site editor's iframe so that they have access to the padding/margin CSS variables for content. But they were still incorrectly receiving the iframe offset.

How?

Adds an extra check to see if the popover and its reference/anchor element are in the same document. This required gaining access to the floating element's owner document, which adds a little bit of extra code.

Testing Instructions

  1. Open the site editor
  2. Insert a cover block
  3. Adjust padding / margin
  4. The visualizers should match the block position

Screenshots or screencast

Before

Screen Shot 2022-09-08 at 4 30 22 pm

After

Screen Shot 2022-09-08 at 4 29 51 pm

@talldan talldan added [Type] Bug An existing feature does not function as intended [Feature] UI Components Impacts or related to the UI component system labels Sep 8, 2022
@talldan talldan self-assigned this Sep 8, 2022
@talldan talldan marked this pull request as ready for review September 8, 2022 08:41
Copy link
Contributor

@jasmussen jasmussen left a comment

Choose a reason for hiding this comment

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

Excellent, thank you for working on this! Here's a GIF showing the padding visualization looking correctly in both the post editor and the site editor:

offset

Code looks good, but would appreciate a sanity check. It seems like this did not have anything to do with the root padding property after all!

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks Dan! 💯

packages/components/src/popover/index.tsx Show resolved Hide resolved
@talldan talldan merged commit 1336026 into trunk Sep 8, 2022
@talldan talldan deleted the fix/padding-margin-visualizer-placement-in-site-editor branch September 8, 2022 10:31
@github-actions github-actions bot added this to the Gutenberg 14.1 milestone Sep 8, 2022
@ciampo
Copy link
Contributor

ciampo commented Sep 8, 2022

Thank you Dan 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Padding visualizers do not work properly in the Site Editor
4 participants