question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can SVG icons have fill:currentColor by default?

See original GitHub issue

What package(s) are you using?

  • @carbon/icons-react
  • carbon-components
  • carbon-components-react

Summary

Hello. I am wondering why SVG icons don’t have fill: currentColor by default. Thus, it will inherit the color property of its container. This simplifies the process of setting the color a bit.

Of course, I can create a HOC / wrapper for the icons where I do this myself.

I was just curious if you had any reasons for not having it and what those might be.

Relevant information

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
joshblackcommented, Jul 9, 2020
0reactions
SimonFinneycommented, Jul 9, 2020

This appears to cause regression in dark themes in cases where the icon is dependent on a fill from its parent - here’s an example of the Search component:

Default

This is resolved by removing the currentColor on the icon as per the original behavior:

currentColor removed

But also if the color of the parent is set to the fill value:

color

We can use this as a workaround for now, but I wanted to raise it for awareness as I suspect this may be a silent issue reoccurring elsewhere and could easily be overlooked on lighter themes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

currentColor and SVGs | Go Make Things
If you don't specific a fill or stroke on your SVG, it defaults to #000000 , or black. The current text color on...
Read more >
Color for SVG icons and elements with currentColor
Making reusable SVG icons and consistent color theme for components while keeping the style sheets short is now achievable with currentColor ...
Read more >
Un-repeat SVG icon fill with currentColor | by David DeSandro
Rather than repeatedly setting both color and fill , you can set fill: currentColor . You need only to set currentColor on the...
Read more >
Cascading SVG Fill Color - CSS-Tricks
One time someone told me their biggest problem with SVG icons is that they didn't match the color of text they were by....
Read more >
How to preserve default SVG color with mat-icon?
the default color of the SVG content is the CSS currentColor value. This makes SVG icons by default have the same color as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found