-
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
Image Block: Keep selected size on changing image #39457
Comments
Hi, |
The issue still exists on trunk. I added a PR to fix the issue. |
Thanks @gaambo I will remove the needs testing label |
Is there any plan to add this to a milestone? This makes it difficult to maintain consistency in block patterns that rely on a specific image size to be set and selecting the image clears it out. |
I think this issues is a real pain when building patterns or templates for clients. We keep telling the client to always update the image size after changing the image, but since the image size is set in the pattern and we generate the image size for all images, this could easily be done programmatically as is seen in my very small PR. |
Just tested with current trunk after #51545 is merged. I thought it may be already fixed, because that PR keeps the aspect ratio when changing images. But the image size is not kept. I can updated my PR after the changes of #51545 but would like to have any feedback if this has a chance to be merged before doing any work. |
Description
When changing the image in an image block, the
sizeSlug
attribute is reset to the default image size or to "full":gutenberg/packages/block-library/src/image/edit.js
Lines 211 to 222 in dfd422a
I think if an image size was already selected before (any other than the default), this should be used again even when changing images.
This is important if the size of the image is important to the layout.
Example: We're using an image block in a pattern for a hero - we've got a custom image size registered for that. I can select the size, but as soon as I click "replace" on the image block, the size gets reset. I have to tell users/editors to change the size again. The width (100%) of the
<img>
element is set via CSS, but of course the image looks bad when inseretd in a smaller image size.I also don't want to change the default image size, since this is only for one pattern and the required/recommended image size may be different for each pattern.
Step-by-step reproduction instructions
Insert an image block in the editor
pick an image
select any other size than the default size
click "replace" and choos another image
the size is reset
Create a pattern which includes an image block with a predefined size
insert the pattern
set/replace the image with any other image
the size is reset
Proposed Solution
Change the code linked above to keep the
sizeSlug
attribute if one was set before and if the new media is available in this size.Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: