Skip to content
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

Prevent dragging element when interacting with its children elements #827

Closed
danylo-holovenko opened this issue Jul 11, 2022 · 4 comments
Closed

Comments

@danylo-holovenko
Copy link

danylo-holovenko commented Jul 11, 2022

Is there any way to prevent element dragging while interacting with its content? It's strange because the Modal component is a portal, which means it's not inside the draggable element's DOM.
If I move the modal outside the draggable component it works fine, but due to project structure it is required that the modal should be inside the draggable component

Example: https://codesandbox.io/s/dnd-kit-portaled-input-forked-kfskb8?file=/src/SortableItem.js

Screen.Recording.2022-07-11.at.14.25.22.mov

Thank you!

@awgv
Copy link

awgv commented Jul 13, 2022

Hey,

It's strange because the Modal component is a portal, which means it's not inside the draggable element's DOM.

It doesn’t matter—that’s how event bubbling works through portals in a React tree, and here’s the relevant thread (facebook/react#11387) if you want to read the whole thing. Take a look at this solution; adding event handlers to the div at line 56 works, but I’m not sure which drag/mouse events you need to keep, so you’ll have to sift through them all.

@danylo-holovenko
Copy link
Author

@awgv It works, thank you!

@josias-r
Copy link

Just saw this issue too, after ending up on that react issue, after I opened a very similar issue in this repo:
#913

Not sure if that workaround with stopPropagating directly inside the portal is good enough for us, because we don't have direct access to the Portal instance, since the modal is from a library too.

But I will certainly check out what options we have, something similar on a lower level might work for us too.

@davidystephenson
Copy link

I was able to solve the problem by stopping the mouseDown event from propagating on the children.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants