Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing grid item click event in react-grid-layout

Is it possible to capture the grid item's click and cancel the drag event? I want to open a modal window when a grid item is clicked, but I can't figure out how to implement this. I'm capturing the click with onClick, but stopPropagation and preventDefault don't prevent the mousedown event that starts the dragging process.

like image 494
nnyby Avatar asked Mar 09 '26 11:03

nnyby


1 Answers

This can be done by passing a onMouseDown to a child div element.

<RGL ... >
  <div> // If you add onMouseDown here react-draggable will override it. You will have to use nested element to capture clicks
    <div onMouseDown={ e => e.stopPropagation() }>
      ...
    </div>
  <div>
</RGL>
like image 130
Ricky Han Avatar answered Mar 11 '26 02:03

Ricky Han



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!