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

BUG: Unable to use transparent fill in Block media svg #6318

Closed
2 tasks done
tonypapousek opened this issue Nov 20, 2024 · 3 comments
Closed
2 tasks done

BUG: Unable to use transparent fill in Block media svg #6318

tonypapousek opened this issue Nov 20, 2024 · 3 comments

Comments

@tonypapousek
Copy link

tonypapousek commented Nov 20, 2024

GrapesJS version

  • I confirm to use the latest version of GrapesJS
    • grapesjs@0.22.3 when this issue was filed

What browser are you using?

Firefox 132, Chrome 131

Reproducible demo link

https://jsfiddle.net/x54f9v68/1/

Describe the bug

How to reproduce the bug?

  1. Add a custom block, with the media property set to an SVG with a transparent fill
  2. Check the blocks tab, and
    notice the fill is automatically set to currentColor

What is the expected behavior?
Fill should be transparent
Screenshot 2024-11-20 at 10 38 00

What is the current behavior?
Fill inheritscurrentColor, which incorrectly renders the icon

Screenshot 2024-11-20 at 10 24 36

Looks like fill is set to currentColor in a few places, but I think this line is the one causing troubles for the block panel.

When I toggle that off in Chrome's style tab, things appear to work:

.gjs-block svg {
    fill: currentColor; // toggle this off 
}

This is one of the flat icons bundled with react-icons. In the actual code, the svg is summoned with:

import { FiLink } from 'react-icons/fi';
import { renderToString } from 'react-dom/server';

const icon = renderToString(FiLink({size: '100%'}));
console.log("icon", icon); // only used to grab the string for reproduction, otherwise passed to the `media` property

Code of Conduct

  • I agree to follow this project's Code of Conduct
@tonypapousek tonypapousek changed the title BUG: Unable to use transparent fill in Block svg BUG: Unable to use transparent fill in Block media svg Nov 20, 2024
@samex
Copy link

samex commented Nov 21, 2024

I believe it depends on the specific SVG being used. If you check the other SVG icons, you'll notice they don't have a fill attribute (inline) on the main tag but rather on the child tags. By setting the fill="none" attribute on the two elements of this SVG, the icon should display properly. I hope this helps you resolve the issue!

@tonypapousek
Copy link
Author

@samex Specifying fill="none" did the trick, thanks! That'll deffo help get my custom stuff working more predictably.

Past that, I think the main pain point would be trying to use third-party SVGs (e.g. "react-icons") or wysiwyg output that doesn't explicitly set the fill attributes. With those use-cases in mind, I'll keep this bug open for now, unless the maintainers prefer it closed.

@artf
Copy link
Member

artf commented Dec 4, 2024

Yeah I'd close this one as it's not strictly related to the core itself but thanks for point this out

@artf artf closed this as completed Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants