Let's say I have a simple code like:
<ListItem
button={true}
>
<Typography variant='caption' color='primary'>
{value}
</Typography>
<Button
onClick={foo}
>
Button
</Button>
</ListItem>
When I click anything inside the ListItem the ripple effect is trigger, which is ok, but when I click the button I don't want the ripple effect of the parent component to be triggered. How do I do that?
Use event.stopPropagation() inside the click handler of the button. In your case, inside the foo() function
You can try to use
disableRipple
property ofListItem
. Set it totrue
when clicking on button and set it tofalse
when clicking on list item, something like:I created a STACKBLITZ to play with
UPDATE
There is a better solution by @Domino987 using
onMouseDown
andevent.stopPropagation()
(already mentioned here by @vasanthcullen).I updated my STACKBLITZ with this solution