Nesting buttons in Material UI: how to disable ripple effect of container button while clicking on a child button?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 23:42:39

问题


I am trying to nest one button into another (IconButton inside ListItem with button prop). The problem is that the ListItem ripple animation gets triggered even if I click on the IconButton. I want it to trigger only if I click directly on ListItem element

I've tried absolute positioning of IconButton, which didn't help

See the example


回答1:


You can either do it like this:

function App() {
  const mouseDown = e => {
    e.stopPropagation ();
  }
  return (
    <ListItem button>
      Some text
      <IconButton onMouseDown={mouseDown}>
        <Favorite />
      </IconButton>
    </ListItem>
  );
}

or by wrapping the Button in <ListItemSecondaryAction>which will also disable the ripple effect, but will move the icon to the end item, which can be fixed with some css.

Hope this helps. Happy coding



来源:https://stackoverflow.com/questions/57374263/nesting-buttons-in-material-ui-how-to-disable-ripple-effect-of-container-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!