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

Nested drop targets and canDrop #1032

Closed
djeremh opened this issue May 29, 2018 · 6 comments
Closed

Nested drop targets and canDrop #1032

djeremh opened this issue May 29, 2018 · 6 comments
Labels

Comments

@djeremh
Copy link

djeremh commented May 29, 2018

I have 2 nested DropTargets.
I want to prevent drop on child droptarget if the drop on parent drop target is disabled.
How can the canDrop() method of the child depend on the canDrop() method of the parent?
I didn't find a way to do that strictly with the current API, I had to rely on components.

Has anybody struggled with this?

Thanks!

@djeremh djeremh changed the title Nested drop target and canDrop Nested drop targets and canDrop May 30, 2018
@danielrob
Copy link

I came here initially because I had the opposite problem... which I solved with monitor.isOver({ shallow: true }) in the canDrop method of both parent and child. I wanted only the child to respond, but found the parent returning false prevented the child from returning true.

Thus I think the behaviour you're describing should be the default behaviour. I'm assuming both accept the same drop types, and that your actual dom elements don't have some wierd stacking issue going on, and that your canDrop isn't getting in the way.

Anyway, I'm not a contributor/collaborator, and just found your issue by chance. You may wish to post a sandbox of your issue, as this always helps library maintainers understand exactly your problem.

@stale
Copy link

stale bot commented Jul 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 6, 2019
@stale stale bot closed this as completed Jul 13, 2019
@andrewvarga
Copy link

@danielrob how did you solve your problem with {shallow: true} ? I'm trying to use that in canDrop and it seems to have no effect. Ideally I would want the children to have priority when dropping, and then the parents.

@bkrmendy
Copy link

Hi Andrew! I solved this, what I did is that I called

if (monitor.didDrop()) {
  return;
}

at the beginning of drop in the parent drop context.

Hopefully this helps you too.

@andrewvarga
Copy link

Hi Andrew! I solved this, what I did is that I called

if (monitor.didDrop()) {
  return;
}

at the beginning of drop in the parent drop context.

Hopefully this helps you too.

oh, thanks! I have to dig up where I used this but it looks useful:) Nice to see familiar faces here!

@mahmoudilyan
Copy link

Look this problem is related to the library itself, when you hover the dragged element into a nestable droppable element. The data you are passing to the droppable element might overlap with the droppable parent or one the ancestors droppable elements. Pass this line in canDrop to take data only from the current Hovered
Take a look how I fix it in my code
`
const handleCanDrop = useCallback((item: any, monitor: any) => {

if (!monitor.isOver({ shallow: true })) {
  return false;
}
const component: IComponent = ComponentsLibrary.getComponentByName(item.name) as IComponent;
const { isMatch, errorMessage } = checkDropRestrictions(component.dropRestrictions, elementRoot);
if (!isMatch) {
  setInvalidDroppingMessage(errorMessage);
} else {
  setInvalidDroppingMessage("");
}
return isMatch;

}, [elementRoot]);
`

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

No branches or pull requests

5 participants