I have this scenario, where when parent element is clicked, it flips to show a child element with different colours. Unfortunately, when the user clicks on one of the colours, the 'click' event on parent is also triggered.
How can I stop the event trigger on parent when the child is clicked?
Possible solutions I am wondering:
CSS?
Append pointer-events : none
class to the parent when the child is clicked. However, this would mean that the parent will need to be cleansed of the pointer-events
class later.
Using Ref?
Record the ref
of the parent React
element & upon click on the child, compare the event.target
against the ref? I don't like this because I don't like the global ref
.
Thoughts and the better solution would be much appreciated. The question is:
How can I stop the event trigger on parent when the child is clicked?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…