-
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
Prevent the image from being resized larger than its container #45775
Prevent the image from being resized larger than its container #45775
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @d-alleyne! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
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 PR! I haven't tested the branch yet but left some initial recommendations and questions.
const maxWidthBuffer = maxWidth * 2.5; | ||
// vanilla editor style. We'll use the clientWidth here, to prevent the width | ||
// of the image growing larger than the width of the block column. | ||
const maxWidthBuffer = clientWidth; |
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.
Should we compare with maxWidth
here and choose the minimum?
const maxWidthBuffer = clientWidth; | |
const maxWidthBuffer = Math.min( clientWidth, maxWidth * 2.5 ); |
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.
@kevin940726 I believe the goal of this commit is to prevent the image from being larger than its container (clientWidth
). Is there an instance where maxWidth * 2.5
is smaller than the container?
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'm not sure! It's a question and I'm not very familiar with the maxWidth
settings. I think it's fine to keep just the clientWidth
though.
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'm not familiar with the constraints of the image block but this tests good to me. Unless there are objections, I'd say let's merge this. We can always revert if we're missing something 🙂 .
I'd be nice if we could add some e2e tests for this, but it might be too complicated 🤔 . |
Oh, we might want to also add a changelog entry for this? |
@kevin940726 Is anything else required of this? |
Thanks for your patience! Due to a recent CI change, could you help rebase it again to get them green again? I'm not sure a changelog entry is required here, maybe not! I think once the CI is green we can merge this 👍 |
What?
On drag to increase the size of the image, it goes outside of the viewport. This PR fixes the issue by preventing the image from being larger than its container.
Why?
It resolves #26715 . Prevent dragged images from being larger than their container.
How?
The
clientWidth
variable contains the width of the container, and it is used as themax-width
for the image.Testing Instructions
Screenshots or screencast