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 an item being dropped into it’s self or any child droppables. #113

Open
sami616 opened this issue Sep 2, 2024 · 1 comment
Open

Comments

@sami616
Copy link

sami616 commented Sep 2, 2024

Is there an example anywhere that shows how to prevent a draggable from being dropped into itself, or any droppables inside of it.

Working with a tree like structure. I have a feeling that I need to use location.current.deopTargets. But I don’t have access to that info inside of the canDrop callback. Is there a recommended way perform this kind of validation?

@sami616
Copy link
Author

sami616 commented Sep 3, 2024

For anyone else who might have a similar issue, I managed to solve my problem like so:

Appreciate this isnt very 'reacty' but it it solves my problem in the simplest way.

 canDrop: ({ source, element }) => {
   // assumes drag handle is inside droptarget
   const sourceEl = source.element.closest('[data-drop-target-for-element="true"]')
   if (sourceEl?.contains(element)) return false
   return true
}

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

1 participant