-
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
Fix padding and margin visualizer accuracy #49422
Conversation
- Use the computed CSS value instead of the non-computed value - Add a small transition to smooth out the delay in resizing
Size Change: +37 B (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
Flaky tests detected in cb0f4c0. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4551002743
|
function getComputedCSS( element, property ) { | ||
return element.ownerDocument.defaultView | ||
.getComputedStyle( element ) | ||
.getPropertyValue( property ); |
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.
So this function transforms the value to pixels or something?
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.
Seems like it. cool.
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 is cool.
What?
I've noticed on a few occasions that the padding and margin visualizers can be incorrect.
In #49392 (comment) I figured out why this is.
It happens for themes that use relative CSS units for spacing presets.
The visualizers are rendered in a popover slot, outside the editor canvas iframe. This means units like
vh
,vw
,rem
andem
might be computed incorrectly because they're using font size and the viewports size of the top level document, not those from the editor canvas document like the block uses.How?
There are two ways that I considered fixing this:
I went with option 2 because it's easier and seems to work correctly
Testing Instructions
Screenshots or screencast
Before
Kapture.2023-03-29.at.14.31.48.mp4
After
Kapture.2023-03-29.at.14.33.38.mp4