clauderic / react-sortable-hoc

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️
https://clauderic.github.io/react-sortable-hoc/
MIT License
10.8k stars 979 forks source link

onShouldSortOver #545

Open ditiem opened 5 years ago

ditiem commented 5 years ago

I need a callback or a way (event.preventDefault()?) to determine if a SortableElement can be dragged to the position is being sorted.

It technically looks like a simple:

if ( !onShouldShortOver(...) ) 
    return ;

in the handler that determines the the element takes a new place.

Could this feature be implement or any hint to do a PR?

Dragomir-Ivanov commented 5 years ago

@ditiem Did you resolved this issue?

ditiem commented 5 years ago

@Dragomir-Ivanov In short the answer is yes. But the project uses a complex testing system that did not work well in my local machine and I do not know why it does not pass the tests (even on a new fresh project). You can check the PR:

https://github.com/clauderic/react-sortable-hoc/pull/547

Main changes are on the first commit:

https://github.com/clauderic/react-sortable-hoc/pull/547/commits/b569fca02595c974c0c2032c40ceba6ad197c7d2

After I added this feature, I found myself adding another 5, and at the end I rewrote the core of the library. I dont remember the main reason, but I think it was that the algorithm used to detect on which position the row should be fails if a row height is greater than the 2 previous rows (or something like that).

Dragomir-Ivanov commented 5 years ago

@ditiem Thanks mate! In ditiem/react-sortable-hoc I see only this feature added. Did you pushed somewhere your further work, or it is proprietary?

ditiem commented 5 years ago

@Dragomir-Ivanov I think this was the last branch before I started to refactor the whole thing.

https://github.com/ditiem/react-sortable-hoc/tree/create-helper

IMHO the whole project should be rewritten in TS, with unit testing and so on. It is not a complex task but it will take 5 days that I do not have now. This project i could share without any problem, as a gratitude to clauderic and/or the community.