-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Post Featured Image]: Try fix max-width sizing issues #50370
Conversation
Thanks for the followup, seems like this just need a quick code check! |
Size Change: +79 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
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.
While the fix tests well for TT3 and even TT1 themes, it won't work for most classic themes. This is because they don't define contentSize
and wideSize
that could be used as fallbacks.
Try testing with Twenty Twenty.
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.
Thanks for looking into this! As per my comments below, this approach has the limitation of not being aware of the parent layout, which should determine if max content width is applied or not. Unless the parent's layout type is "constrained", we shouldn't limit the content width at all.
The problem is that for the front end we don't have access to the parent layout settings.
I wonder if we couldn't instead use the same approach as in the Image block, where any fixed width value in the front end gets applied to the img
element, so it can't override any max-width set by layout on the block outer wrapper.
// Depending on the `align` value we need to set a different max-width | ||
// to restrict properly the image size. | ||
if ( ! align ) { | ||
style.maxWidth = 'min(100%, var(--wp--style--global--content-size))'; |
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 should only output this style is there is a width set, otherwise if there's no align and no width the block works fine as it is.
The other thing we should be checking here is parent layout, because this rule only makes sense for a child of a constrained type layout. There's an __unstableParentLayout
prop that gets passed into the block edit function that can help with that 🙂
@@ -92,7 +92,13 @@ function render_block_core_post_featured_image( $attributes, $content, $block ) | |||
if ( ! $height && ! $width && ! $aspect_ratio ) { | |||
$wrapper_attributes = get_block_wrapper_attributes(); | |||
} else { | |||
$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $aspect_ratio . $width . $height . 'max-width:100%;' ) ); | |||
$max_width = ''; | |||
if ( empty( $attributes['align'] ) ) { |
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.
It would be good to check the parent layout before outputting these rules here too, but there's no way to access it currently from the block's render callback function. Maybe we need a slightly different approach here 🤔
Thank you for the feedback! I've opened a PR to revert this change and give us time to think this through better. |
What?
Follow up of: #49641 (comment)
The above PR tried to fix some sizing issues with Post Featured Image, but introduced a regression.
This PR tries to constraint the max-width based on the alignment, but I'm not sure of all the nuances here and we might end up reverting the original PR.
This PR while it seems to handle properly the
wide, none
alignments, doesn't prevent the overflowing of images when we have set afull align
and a bigwidth
in the block settings. Noting though that this will still be the case by reverting the original PR. Any ideas or insights maybe from @tellthemachines would be much appreciated!Testing Instructions
full
align.