react-icon disappeared
I am facing this weird bug in my application. Some of my icons disappear, while inspecting with dev tools the SVGs are there but it doesn't appear in the UI. While trying to figure this out I got the solution but I want to know what coausing this
what happens is if I set the size of icon 18 it appears anything below
18
it disappears again
<ToolTipIcon size={18} />
this is visible
but <ToolTipIcon />
this is not, but its SVG is there in the DOM44 Replies
To know for sure, it'd be nice to have a snippet where it is being used
Actually it's not about where I am using it it's happening through out application
you're sharing an invocation of a component, without any info about what that component is
for all we know, there's a
if size < 18 then display: none;
in there somewhere
this question is unanswerable without more information, like the code that's being runI am working with React tailwind
react-icon
and this is happening throughout the application
The icon that was working fine because is now not visible
So idk what exactly to share am sorry about that
Please tell me what part of code should I share
you could start with showing the svg when it is not visable (inspect element). if we can see what is missing, why might have an idea
for eg. there should be an icon beside Verified
__
another example
icon beside revenue
it is working
if i decrease the height of it
there's no issue
but if i decrease the width of it less then 18 it'll disappear
when i look at the viewbox, it is supposed to be square (0 0 24 24). so instead of only setting the hight, you might also try to set the width
i am using
react-icon package
so when we set size to it
it sets the both height and width
like this
this is one of the examples of how am using thiscan you pase the whole svg code of an icon please.
from dev tools?
yep
using it here
it might be the tailwind classes border, padding. (those are included into the size, so there wont be space left)
it appears when i add
overflow: visible;
what happens if you remove the p-2
but my doubt is it was working fine when i coded it for the first time
and i dont know by when or i did change something
all this icon disappeard and now the y do appear if i change some property like this overflow or if i cange the size
well, if your icon size is 18px but has the padding (p-2 = 8px), there will only be 2px left to fit the svg
what should i do in this case
should i give height ad width to this insted of padding for breathing space
or set the size on the svg and put it in a separate element with the padding and border
this works
yea. or remove w-8 h-8 from the span and use p-2 instead (then you also wont need the flex center)
this worked
thankss!
no problem. glad it works.
I'll have to do changes to all these icons that disappeared
and am still not clear why it was working before and not now :/
when you set a size to an element, and you include padding, that padding takes space of that size. so imagine
svg is 16x16px
padding is 8px (2x for all directions)
then 16px - 16px = 0px left for the svg itself
makes sense
what about here? @MarkBoots
for me it works
this works for me if am settinf the font size = 18px to svg
---
if i do flex-grow on svg (without adding the size)
this happens
---
or adding this
overflow: visible;
works 🥲Hard to tell, but you need to try and stay away from styling an svg itself. it can effect everything inside the viewbox. put a span around it.
got it
i'll do that
@MarkBoots i got to know another thing please check if this can help you understand this
when i am inspecting its the same as is the icons are not visible
but as soon as i hit thhe responsive button on dev tool
all the icons are visible no matter the screen size we select in responsive
uhm, not sure. that could be a quirck of the responsive mode of the browser (it only tries to emulate it, it's not exact what a device would do). also maybe the zoom level makes it possible to show up... can not tell, don't know
so after digging alot ALOT!
here's the problem
ifi comment this then all the icons work perfectly