question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Option to remove item when dropped outside of container.

See original GitHub issue

Maybe I missed something much simpler (I sure hope not…), but it took me quite a bit of playing around with the current API to make this work.

In case anyone needs this functionality too, here’s how I did it: I ended up tracking when the dragged item would leave its original container’s bounds, and whether it moved back into it (dragEnter, dragLeave).

I also needed to track if the dragged item entered the bounds of any other containers that returned should-accept-drop as true, because onDrop fires too late for me to interrupt the drag end animation in case it wasn’t dropped.

Then I had to implement a mouseup listener on an upper level container so it would catch the drag release (dragEnd fires too late) and modify the style attributes applied as follows:

// transitionProperty order: left, top, opacity, transform
ghostEl.style.transitionDelay = '5s, 5s, 0s, 0s'
ghostEl.style.transitionDuration = '0.25s'

I was unable to figure out a way to set the transition attributes beforehand, as doing so would affect the animation of dragging the ghost too. There is a position: left & top applied to the ghost item when it is released to simulate it “returning” to its original spot. The styles above combined with a scaling effect simulate a disappearing animation (it’s the same one used when you drag items out of a smooth-dnd “copy” container and drop them in the middle of nowhere). shouldAnimateDrop cannot be used for any of this since it’s technically not a drop to release outside of a container.

Originally I had considered wrapping all my drop containers with a “board” container which could then detect drops onto it… but I couldn’t get that to work.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
kutlugsahincommented, Nov 17, 2018

Hey @zerosym Added in 0.2.6 with ‘remove-on-drop-out’ boolean prop. If you set it true then Container will call ‘drop’ with ‘removedIndex’ set. and the moving back animation will become fade out animation. Cheers!

1reaction
davestewartcommented, Mar 13, 2019

Unless you can explain otherwise, I think perhaps this is where an onDropComplete handler would be invaluable - in this case, with a removedIndex but no addedIndex:

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to drag and drop items to external container?
Now, I want to be able to drag and drop items from the list to that "external" container. When user "drops" item to...
Read more >
HTMLElement: drop event - Web APIs | MDN
The drop event is fired when an element or text selection is dropped on a valid drop target.
Read more >
Drag and drop UI elements in Flutter with Draggable and ...
This demonstration walks through how to build drag-and-drop interactions in a Flutter app with Draggable, DragTarget, ...
Read more >
Release artifacts and artifact sources - Azure Pipelines
The Artifacts Default version drop down list items depends on the repository type of the linked build definition. The following options are ...
Read more >
Select, move, and order objects – Figma Help Center
To remove an object from the selection, hold down the Shift key and click on the ... Right click an object and select...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found