Skip to content

Ensure SVG Images Without a Width Attribute Are Displayed Correctly in FocalPointPicker #70061

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

Merged

Conversation

vk17-starlord
Copy link
Contributor

What?

This PR addresses and fixes Issue #43869, where SVG images without a width attribute were not displayed correctly in the FocalPointPicker component. The issue arose because such SVG images defaulted to width: 0, rendering them invisible in the UI.

The fix ensures that SVG images are displayed properly by enforcing the following styles via CSS:

  • width: 100% to make the SVG scale appropriately.
  • height: auto to maintain the aspect ratio of the SVG.

Why?

Previously, when an SVG image lacking a width attribute was uploaded and used with the FocalPointPicker component, the image would not display properly due to its width defaulting to 0. This created a poor user experience, as users could not adjust the focal point for SVGs. The fix ensures consistency across different types of images used with the FocalPointPicker component.

How?

The implementation involves:

  1. Updating the styles applied to the FocalPointPicker component.
  2. Adding CSS rules to enforce width: 100% and height: auto for SVG images, ensuring they are displayed properly while maintaining their aspect ratio.

Testing Instructions

To test this PR:

  1. Open the block editor in WordPress.
  2. Add a block that uses the FocalPointPicker component (e.g., a Cover block).
  3. Upload an SVG image that does not include a width attribute (e.g., use the SVG file provided in Issue #43869).
  4. Verify that:
    • The SVG image is displayed correctly within the FocalPointPicker.
    • Adjusting the focal point works as expected.
    • No regressions occur for other image types.

Screenshots

Before After
Before Screenshot After Screenshot

Additional Notes

This fix ensures compatibility and a better user experience for users working with SVG images in the block editor. It has been tested to verify that other image formats and features of the FocalPointPicker component are unaffected.

Closes #43869.


Previously, SVG images without a width attribute were not displayed correctly
in the FocalPointPicker component as they defaulted to width: 0. This fix
ensures SVG images are properly displayed by using width: 100% and
maintaining aspect ratio through height: auto in the styled components.

Fixes WordPress#43869
@vk17-starlord vk17-starlord requested a review from ajitbohra as a code owner May 5, 2025 20:06
Copy link

github-actions bot commented May 5, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: vk17-starlord <vineet2003@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: artemiomorales <artemiosans@git.wordpress.org>
Co-authored-by: lichtmetzger <dscqbus@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels May 7, 2025
@Mamaduka
Copy link
Member

@vk17-starlord, do you mind adding a changelog entry for this fix? It could be something along these lines. You can see style examples in changelog.md file.

FocalPointPicker: Fix SVG display when it doesn't provide a width attribute.

@vk17-starlord
Copy link
Contributor Author

@Mamaduka I have added changelog entry for this fix

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @vk17-starlord!

@Mamaduka Mamaduka merged commit 9b48761 into WordPress:trunk May 27, 2025
60 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.0 milestone May 27, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…n FocalPointPicker (WordPress#70061)

Co-authored-by: vk17-starlord <vineet2003@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: artemiomorales <artemiosans@git.wordpress.org>
Co-authored-by: lichtmetzger <dscqbus@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FocalPointPicker: SVG images without a width attribute are not displayed
2 participants