mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[DataGridPro]: Clicking inside checkbox for rowSelection fires onRowClick

Open pkuzhel opened this issue 4 years ago • 4 comments

Duplicates

  • [X] I have searched the existing issues

Latest version

  • [X] I have tested the latest version

Current behavior 😯

In Data Grid Pro >v5.3, a click on selection checkbox (which appears with checkboxSelection) now also fires onRowClick

This seems like a regression. Couldn't find anything in docs or changelog around this change

Expected behavior 🤔

In Data Grid Pro <v5.3 with option checkboxSelection, clicking on checkbox, would only select the row, but not fire the onRowClick

I don't expect onRowClick to fire on rowSelection (using the dedicated checkbox)

Steps to reproduce 🕹

Example for v5.3 [expected behaviour]: https://codesandbox.io/s/disableclickselectiongrid-material-demo-forked-4fj2j?file=/demo.js

Click on checkbox and observe console.log (nothing should happen)

Example for v5.5 [latest]: https://codesandbox.io/s/disableclickselectiongrid-material-demo-forked-3w6jo?file=/package.json Click on checkbox and see the onRowClick executing in console

Context 🔦

We have a data-grid-pro license and this introduced a bug into site. We have to pin the version to 5.3.0 for now until this is fixed.

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
This bug is reproducible in Chrome/Firefox Windows/Mac OS X

Order ID 💳 (optional)

#31725

pkuzhel avatar Feb 09 '22 03:02 pkuzhel

Duplicate of #3805 You may find https://github.com/mui/mui-x/issues/3805#issuecomment-1026999591 useful. Does it solve your issue?

cherniavskii avatar Feb 09 '22 09:02 cherniavskii

Yep, the workaround works.

I am concerned that if __check__ was ever to change, it would cause another breaking change for our application.

It seems like both options would be useful.

Would it be possible to add an option (similar to disableSelectionOnClick to call event.stopPropogation)?

Another options would be to add rigid definition of the type of click? Similar to how the onClose of modal works with the reason https://mui.com/api/modal/#main-content

But for now, thanks for solving my immediate issue.

pkuzhel avatar Feb 09 '22 15:02 pkuzhel

@pkuzhel

I am concerned that if check was ever to change, it would cause another breaking change for our application.

You can use GRID_CHECKBOX_SELECTION_COL_DEF.field instead - see this example

Would it be possible to add an option (similar to disableSelectionOnClick to call event.stopPropogation)?

Do you have a use case for it?

cherniavskii avatar Feb 09 '22 16:02 cherniavskii

It seems that the change we did to fix the focus caused problems. I propose that we use cellClick for the selection and only fire rowClick when the target is not the checkbox column or any other column that contains interactive elements (row grouping columns, actions column and master/detail toggle column).

https://github.com/mui/mui-x/blob/23cf2fe41a2141c42c6258daec28e73df3b78aee/packages/grid/modules/grid/hooks/features/selection/useGridSelection.ts#L441

m4theushw avatar Feb 09 '22 19:02 m4theushw