-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using ContextMenu2 with table rows #4619
Comments
did you try this? const getRowContextMenuHandler = (rowData: MyData) => () => {
// Do something with rowData, like 'selectMyRow(rowData)' which then changes the rows color...
};
const getRowContextMenu = (rowData: MyData) => {
// return menu content here
};
return (
<ContextMenu2 content={getRowContextMenu(rowData)} onContextMenu={getRowContextMenuHandler(rowData)}>
<tr>{...}</tr>
</ContextMenu2>
); |
Given your example, and as I understand So instead of (which is valid HTML table markup): <table>
<tbody>
<tr>...</tr> <!-- onContextMenu={handleContextMenu(rowData)} -->
<tr>...</tr> <!-- onContextMenu={handleContextMenu(rowData)} -->
<tr>...</tr> <!-- onContextMenu={handleContextMenu(rowData)} -->
...
</tbody>
</table> Your example would result in something like (which is invalid markup): <table>
<tbody>
<div> <!-- This div is a result of `<ContextMenu2>` -->
<tr>...</tr>
</div>
<div> <!-- This div is a result of `<ContextMenu2>` -->
<tr>...</tr>
</div>
<div> <!-- This div is a result of `<ContextMenu2>` -->
<tr>...</tr>
</div>
...
</tbody>
</table> Also, wrapping each row with |
Ok, then you can try flipping the DOM ordering: <tr>
<ContextMenu2 ...>
</tr>
By what metric? Each context menu has different information about the row, so this is fairly idiomatic React IMO. There may be a separate feature request here for having ContextMenu2 not generate a wrapper element (similar to how Popover2's |
Won't that result in invalid HTML markup as well? <tr>
<div> <!-- This div is a result of `<ContextMenu2>` -->
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</div>
</tr> |
Hm, you're right. I will need to spend some more time thinking about this... I'll make sure to figure out a way to support this use case before the final 4.0.0 release. |
I added a new API in #4635 which should address the problem here, it will allow you to omit the |
Thank you! I'm personally fine with this being 4.0 only feature as |
ported to develop and fixed by #4640 |
It is idiomatic React in one way of thinking, but it is also idomatic React that an event handler, such as onContextMenu is handled by a function or method such as ContextMenu.show(...). Not having an imperative option adds inefficiency in the case of large collections (even in a virtualized table wrapping every cell in a ContextMenu2 increases scrolling jankiness because you're asking the virtual dom to do a lot more work). I think it's a mistake not to have an imperative option, and seems that they way you've designed it that is truly not an option because the isOpen prop is gone and is only now passed to the content as a read-only prop rather than being controllable from the outside. |
With
ContextMenu
I had the ability to use "imperative" API when working with table rows:Something like...
How can I achieve something like that with
ContextMenu2
?If I wrap entire table with
ContextMenu2
then I would need to drill down using React/HTML API in order to get the data associated with the row I right-clicked on.The text was updated successfully, but these errors were encountered: