adazzle / react-data-grid

Feature-rich and customizable data grid React component
https://adazzle.github.io/react-data-grid/
Other
6.89k stars 2.17k forks source link

Resizable feature doesn't work alongside the "Menu" component from Material UI #2897

Closed BPernes closed 8 months ago

BPernes commented 2 years ago

Describe the bug

grid-example

redline-example

This problem will not happen if the resizable option in setted to "false"

bug-example

To Reproduce

  1. Create a DataGrid
  2. Implement a HeaderRenderer who implements a "Menu" component from material ui v4
  3. Set the column propertie "resizable" to true
  4. Set the Menu component to be next to the column resize line
  5. Try to click the button after the column resize line

Expected behavior

Environment

ivan-palatov commented 2 years ago

Can you give a codesandbox with the issue you are having? Since the hover effect is working, I'd assume that e.stopPropagation() on click event would resolve the issue. Try creating a component like this

interface IProps
  extends React.DetailedHTMLProps<
    React.HTMLAttributes<HTMLDivElement>,
    HTMLDivElement
  > {}

const stopPropagation = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) =>
  e.stopPropagation();

const StopPropagation = observer<IProps>(({ children, ...props }) => {
  return (
    <div {...props} onClick={stopPropagation}>
      {children}
    </div>
  );
});

And wrapping it around your menu/menu items.

rsmaan4u8 commented 2 years ago

I have noticed the same problem. Below is the link to code sandbox.

https://codesandbox.io/embed/material-demo-forked-9yu2en?fontsize=14&hidenavigation=1&theme=dark @ivan-palatov tried your suggestion but it does not work. I think it is something to do with portal. Please note that grid is in Dialog.

izmy commented 2 years ago

Well, I resolved this problem by condition in file ResizableHeaderCell:

if (event.target.className !== "rdg-header-cell-resizer") return;

scottostler commented 2 years ago

I'm also seeing this issue with @szhsin/react-menu. I was able to work around this by adding onPointerDown={e => e.stopPropagation()} in my column header's menu component