Error on resize image.
Hi Ronaldo, I'm not sure if there is a simple way to fix this behavior globally for all use cases as you're resizing the image for both sizes and not only the width (in that case the height wouldn't change). What I can suggest trying is to extend the image component with this option for resizable Let me know if that w...
Read full answer below βQuestion
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Brave Browser Last version
Reproducible demo link
https://grapesjs.com/demo.html
Describe the bug
How to reproduce the bug?
- Opens the demo page.
- Puts an image.
- Double click to select image.
- Set width to 100%.
- Set height to auto or click on the
xin height property. - Resize image, you will see that width keeps in % and height is calculated in pixels
- Click on the preview eye
- See that the image is flattened.
What is the expected behavior? Resize algorithm should calc in pixels instead of mix them
What is the current behavior? Resize function are keeping % as main css unity and calculating the height with pixels, but, when we click in the preview button, the size of column changes, so, the width in % steel working, but the height in pixels is broken.
Check the video with the bug happening: https://www.loom.com/share/f2ed011b207a4e5fb2ac916c94ab0a5b
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (4)
Hi Ronaldo, I'm not sure if there is a simple way to fix this behavior globally for all use cases as you're resizing the image for both sizes and not only the width (in that case the height wouldn't change).
What I can suggest trying is to extend the image component with this option for resizable
resizable: { ratioDefault: true, keepAutoHeight: true }
Let me know if that works for you
Hi @artf. One way we thought to fix this for our use case based on our users is to change the units for width and height always together. That means when the user changes the width from pixels to %, for example, the height will also be changed to %. Is there a way to do this? Also, how can we change the resizer to use % as the default unit?
Let me know if that works for you
Hi Arthur, these configuration didn't make any changes to the image, it keeps setting the height with px instead of auto, as property keepAutoHeight suggest
Thanks for reporting this, @ronaldohoch.
Great question about Error on resize image.. The recommended approach with StyleManager is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4208
Style click state bug in every element
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Brave Last, tested on chrome last and Safa...
Issue #5583
Can't set background:none in mobile version using styles panel
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Edge last version Reproducible demo link h...
Issue #5346
Deleting a component without deleting its corresponding style
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? latest version of Chrome Reproducible demo...
Issue #6549
Couldnt Resize image
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://code...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βRelated tutorials
In-depth guides on the same topic.
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
GJS Market 2.0 - Donations, Tracking, Labels and Better Product Discovery
Weβve rolled out a new set of GrapesJS marketplace updates across GJS Market, focused on improving how creators distribute products
Tutorial
Preset DevFuture 2.0 β New Update Released
Preset continues evolving as a clean, production-ready starting point for building visual editors powered by GrapesJS
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.