-
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: ResponsiveWrapper can not handle cases with small dimensions #20892
Fix: ResponsiveWrapper can not handle cases with small dimensions #20892
Conversation
Size Change: +36 B (0%) Total Size: 857 kB
ℹ️ View Unchanged
|
@@ -15,4 +15,5 @@ | |||
left: 0; | |||
width: 100%; | |||
height: 100%; | |||
margin: auto; |
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.
I guess this centers the small images, I'm not sure it's better than the left aligned images design-wise. That said, I don't have a strong preference.
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.
cc: @mapk to double-check if the design looks ok.
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.
LGTM 👍
I was able after a few tries to get into gutenberg.run to see the results of this fix. The fix looks better then what was seen in the #20697 Example after the fix. God job! Thanks for tackling this issue, Jorge! |
if ( Children.count( children ) !== 1 ) { | ||
return null; | ||
} | ||
const imageStyle = { | ||
paddingBottom: ( naturalHeight / naturalWidth ) * 100 + '%', | ||
paddingBottom: | ||
naturalWidth < containerWidth |
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.
We may want to be conscious of the fact that containerWidth
will be null
the first time the component renders, and in comparisons like this, null
is treated effectively the same as 0
. I'm not sure based on the logic here if that's what we're expecting.
Fixes: #20697
Description
The ResponsiveWrapper component makes sure the elements (normally images) passed to it are resized to the available width and the proportions between width and height are kept.
The component has a bug and does not deal correctly with cases where the width of the children is smaller than the width available for the container.
It applied the following rule style "( naturalHeight / naturalWidth ) * 100 + '%'" this made the container, in a case where the height is 20 and the width is 10 it makes the height 2 times the width. This creates lots of unnecessary space:
We had this bug since the component was created but it was not very noticeable because we did not load thumbnails on the featured images, we loaded full-size images. In WordPress 5.4 we started loading thumbnails and this bug becomes very noticeable as noted in #20697 as almost all the images passed to the component are small.
This PR fixes the issue for small images when the width is smaller than the width of the container we simply make the height equal to the image height.
Screenshots
Before:
After: