I have a bottom navigation list of div elements which each contain a svg icon. When the user clicks on an icon I need the given id property to set the state of which the specific content is then rendered.
I actually figured it out, but the problem with inline svg is that the passed event.target
is either the <div>
, the <svg>
tag or even further down the <path>
. I envision a solution where whenever the user clicks, the event always bubbles up to div.id
and gets returned to be set into state.
Do I need to set a click handeler on every childnode manually or is there another way?
Example:
const Nav = () => {
return (
<nav>
<div id="I-WANT-YOU" onClick={event => whatToDoHere(event)}>
<svg fill="#systemValue">
<path ....long path .... />
</svg>
</div>
.... repeat 5 times
</nav>
)
}
Now I have a dirty solution of setting the svg icon as a background-image: url('path/here.svg');
but the intention with inlining the svg icons is, that I can set user specific fill
values which will not be possible with this solution.
NOTE:
- Yes I am aware of
<ul>
and<li>
, I try to describe the problem as simple as possible. - My knowledge on event delegation is limited and I know about about the
true
parameter on a vanilla click event listener. TheonClickCapture
React documentation did not help me.