If you want to control the ripple effect in a Material-UI ListItem component, you can utilize the disableRipple
property. Simply set it to true
when clicking on a button and set it to false
when clicking on the list item itself. Here's an example:
const disableRipple = () => this.setState(prevState => ({
...prevState,
parentDisableRipple: true
}));
const enableRipple = () => this.state.parentDisableRipple && this.setState(prevState => ({
...prevState,
parentDisableRipple: false
}));
return (
<div>
<Hello name={this.state.name} />
<p>
Start editing to see some magic happen :)
</p>
<ListItem button={true}
disableRipple={this.state.parentDisableRipple}
onClick={enableRipple()}>
<Typography variant='caption' color='primary'>
{value}
</Typography>
<Button onClick={foo} >Button</Button>
</ListItem>
</div>
);
I've created a playground on STACKBLITZ where you can experiment with this setup.
UPDATE
An alternative solution suggested by @Domino987 involves using onMouseDown
along with event.stopPropagation()
, as well as wrapping the contents in a <ListItemSecondaryAction>
wrapper. You can find more details and examples in this thread.
I have updated my STACKBLITZ to showcase both of these solutions.