-
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
Adds Aspect ratio control on Image blocks in Grids #62891
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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 taking this on @amitraj2203!
I think ideally we'd find a solution that doesn't involve DimensionsTool
having to know about layout. Perhaps instead of passing it parentLayoutType
directly, we can introduce an array type prop with a list of tools to render. It could default to all tools, e.g. [ 'aspectRatio', 'widthHeight', 'scale']
, but if we pass it ['aspectRatio'] it only renders the aspect ratio tool. Then we can leave deciding which tools to render based on parent layout type to the image block.
@tellthemachines Updated it as per your suggestion. |
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 iterating on this! The code is looking good now, there's only one small issue remaining. Currently, setting aspect ratio on images in a Grid block results in the images becoming distorted:
This is due to the object-fit
property not being set. In Image blocks outside Grid, cover
is being used as a default value for the scale
attribute, which translates to the object-fit
CSS property. Inside a grid, because we're not exposing the scale tool, I think the best solution is to set the attribute directly in aspectRatioControl
, like so:
setAttributes( {
aspectRatio: newAspectRatio,
scale: 'cover',
} );
Apologies for not spotting this in my earlier review!
Oh, I just noticed something else in testing: the resizable box handles on the Image block are now appearing beneath the grid resizers: We'll need to disable them, but I'm not 100% sure how. Looking into it now. Update: changing the condition on this line to |
Thanks for reviewing it thoroughly. I have addressed the changes. |
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 the update @amitraj2203! This is working well for me now.
What?
Fixes: #62889
Why?
Currently, when adding an Image block within a Grid layout, the Aspect Ratio control is disabled. This can limit user's ability to set consistent visual proportions across images within the grid. Enabling the Aspect Ratio control allows users to maintain uniformity in image display.
How?
Conditionally shows Aspect ratio control on grid layouts.
Testing Instructions
Screenshots or screencast
Screen.Recording.2024-06-27.at.2.56.58.AM.mov