You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MUI表格可点击行内图标按钮点击事件冲突问题求助

分离MUI表格行与内部IconButton的点击事件

问题本质是DOM事件冒泡机制:点击IconButton时,事件会沿着DOM树向上传播,触发父元素TableRow的onClick事件。要实现点击行为分离,只需在IconButton的点击回调中阻止事件冒泡即可。

修改IconButton的代码,添加event.stopPropagation():

<TableCell>
  <Tooltip title='Survey options'>
    <IconButton
      onClick={(event) => {
        event.stopPropagation(); // 阻止事件向上传递到TableRow
        console.log('button clicked!');
      }}
    >
      <MoreHoriz />
    </IconButton>
  </Tooltip>
</TableCell>

这样点击IconButton时,只会执行按钮自身的逻辑,不会触发TableRow的handleRowClick;点击表格行其他区域时,依然会正常触发行的点击事件。

内容的提问来源于stack exchange,提问作者psych0groov3

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 10:10:51