In a Material-UI single-select <Table>, how does one implement in-row controls?

做~自己de王妃 提交于 2019-12-12 02:24:18

问题


I'm implementing an <IconMenu> in each row of a single-select table. <Table onRowSelection= provides an event for tracking the current row. Unfortunately, if the user first selects the row, then clicks on the <IconMenu> the row first sees the click on the <IconMenu> as a deselect, so there's no selected row when the <IconMenu><MenuItem onClick= fires.

I've hacked around some of this (retaining the last-seen selection), but there are still issues; in particular, the row highlight is gone, so the user may be unsure which row they clicked on.

Is there a clean way to inhibit the row-selection behavior altogether when the <IconMenu> in the row is clicked on?

Do you think I should write up an issue on https://github.com/callemall/material-ui?


回答1:


You can work around this behavior by stopping the event propagation in each that contains an <IconMenu>. In order to do this just add a with an onClick handler to each that contains an <IconMenu>. Something like this:

<TableRowColumn>
    <div onClick={(e) => {e.stopPropagation()}}><IconMenu></div>
</TableRowColumn>


来源:https://stackoverflow.com/questions/38110341/in-a-material-ui-single-select-table-how-does-one-implement-in-row-controls

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