Skip to content
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

Merged
merged 1 commit into from
Jan 4, 2023
Merged

Prevent the image from being resized larger than its container #45775

merged 1 commit into from
Jan 4, 2023

Conversation

d-alleyne
Copy link
Contributor

@d-alleyne d-alleyne commented Nov 15, 2022

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 the max-width for the image.

Testing Instructions

  1. Create a post
  2. Add image block
  3. drag the image block from side and bottom.
  4. notice that the image never grows wider than the container

Screenshots or screencast

@d-alleyne d-alleyne requested a review from ajitbohra as a code owner November 15, 2022 15:06
@codesandbox
Copy link

codesandbox bot commented Nov 15, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 15, 2022
@github-actions
Copy link

👋 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.

@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. [Block] Image Affects the Image Block labels Nov 15, 2022
@kevin940726 kevin940726 requested a review from talldan November 21, 2022 01:40
Copy link
Member

@kevin940726 kevin940726 left a 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.

packages/block-library/src/image/image.js Outdated Show resolved Hide resolved
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;
Copy link
Member

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?

Suggested change
const maxWidthBuffer = clientWidth;
const maxWidthBuffer = Math.min( clientWidth, maxWidth * 2.5 );

Copy link
Contributor Author

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?

Copy link
Member

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.

@d-alleyne d-alleyne requested review from kevin940726 and removed request for talldan and ajitbohra November 29, 2022 13:30
Copy link
Member

@kevin940726 kevin940726 left a 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 🙂 .

@kevin940726
Copy link
Member

I'd be nice if we could add some e2e tests for this, but it might be too complicated 🤔 .

@kevin940726
Copy link
Member

Oh, we might want to also add a changelog entry for this?

@d-alleyne
Copy link
Contributor Author

@kevin940726 Is anything else required of this?

@kevin940726
Copy link
Member

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image block can be resized to be larger than viewport
3 participants