Can SVG icons have fill:currentColor by default?
See original GitHub issueWhat 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:
- Created 4 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @SimonFinney! Opened an issue over at: https://github.com/carbon-design-system/carbon/issues/6432
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 theSearch
component:This is resolved by removing the
currentColor
on the icon as per the original behavior:But also if the
color
of the parent is set to thefill
value: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.