PuruVJ / neodrag

One Draggable to rule them all 💍
https://neodrag.dev
MIT License
1.59k stars 48 forks source link

Preventing elements being dragged on top of other elements #119

Open antony opened 1 year ago

antony commented 1 year ago

I guess this ties in a bit with a feature you've named obstacles. As commonly seen in website-builders, or todo-lists, it'd be really useful to have a feature that prevents elements being dragged on top of other elements.

I guess the slight divergence from the obstacles feature would be the behaviour here. I'd like to be able to choose to either prevent dropping of an object by changing the cursor/otherwise indicating that it isn't possible, but more importantly - and this works better if you've got a grid enabled, and if you're restricting movement to a single direction, but I'd like to be able to tell other elements to move out of the way, allowing me space to drop the element. In the case that I dropped it there, the elements would move completely out of the way to accommodate the dropped one.

It's useful when you have a set of blocks and you just want them to be re-arrange-able.

Hopefully this is clear enough but if not, I can find an example!

PuruVJ commented 1 year ago

Hey Antony 👋

Not sure if this is fully in the scope of the library. I could add an option beforeCollide which fires when it is about to hit the obstacle area, and you could perform your logic in that.

How does that sound?