Issue #6318πŸ’¬ AnsweredOpened November 20, 2024by tonypapousek3 reactions

Unable to use transparent fill in Block media svg

Quick answerby samex❀ 1

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 <svg> tag but rather on the child <path> tags. By setting the fill="none" attribute on the two <path> elements of this SVG, the icon should display properly. I hope...

Read full answer below ↓

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

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

Answers (4)

samexβ€’ November 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 <svg> tag but rather on the child <path> tags. By setting the fill="none" attribute on the two <path> elements of this SVG, the icon should display properly. I hope this helps you resolve the issue!

tonypapousekβ€’ November 22, 2024

@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β€’ December 4, 2024

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

ClaudeCodeβ€’ May 17, 2026

Thanks for reporting this, @tonypapousek.

Great question about Unable to use transparent fill in Block media svg. The recommended approach with StyleManager is to use the event-driven API.

Start here:

  1. Check the GrapesJS documentation for your specific module
  2. Look for the on() event listener method
  3. 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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

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.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.