React-sortable-hoc: Do not swallow click events

Created on 28 Dec 2016  Â·  5Comments  Â·  Source: clauderic/react-sortable-hoc

When sorting begins, the click event is swallowed and not passed down to the children.
This makes it tricky for us to react to click events, just as if a user is clicking to highlight, or clicking to receive a popup. Both these events are interpreted as a sort start, and consume the click event.
What could go wrongâ„¢ if the event was propagated down to the children each time ?

Most helpful comment

Currently, there are a number of different approaches already available to get around this:

  • As mentioned by @isaachinman, you can use a SortableHandle
  • You can also use the distance prop to set a minimum distance to be dragged before sorting is triggered (for instance, you could set a distance of 1px like so: distance={1})
  • You can also use the pressDelay prop to set a delay before sorting is triggered.

I believe these should be sufficient to cover most use cases, but I'm open to suggestions if you guys have other ideas.

One caveat to be mindful of: the current implementation relies on cloning the element that is being sorted, so there isn't a way to propagate the click event if sorting begins immediately.

All 5 comments

I had the same issue just barely and thought I'd comment with the workaround I used. #49 talks about using shouldCancelStart to avoid sorting when clicking on certain elements within your sortable item. Hopefully that helps.

Thanks @msiebert - however I still want sorting to start, I just want to receive the click. If I use shouldCancelStart and cancel the sort, I cannot start it again. It just seems that passing the click thru is the right action to take on the component, as it is more consistent.

Was there any resolution to this? @furiousOyster Did you come up with a workaround? A sortable component really isn't very much use if it prevents click events propagating to the sortable things themselves...

Edit: In my own project, I have gotten around this by explicitly using a SortableHandle to ensure that click events and their propagation are more predictable. While the issue was unexpected and a bit annoying at first, I understand how it's more or less unavoidable.

Currently, there are a number of different approaches already available to get around this:

  • As mentioned by @isaachinman, you can use a SortableHandle
  • You can also use the distance prop to set a minimum distance to be dragged before sorting is triggered (for instance, you could set a distance of 1px like so: distance={1})
  • You can also use the pressDelay prop to set a delay before sorting is triggered.

I believe these should be sufficient to cover most use cases, but I'm open to suggestions if you guys have other ideas.

One caveat to be mindful of: the current implementation relies on cloning the element that is being sorted, so there isn't a way to propagate the click event if sorting begins immediately.

@clauderic Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashishtechuz picture ashishtechuz  Â·  4Comments

zhujunwei picture zhujunwei  Â·  3Comments

ricokahler picture ricokahler  Â·  3Comments

therealedsheenan picture therealedsheenan  Â·  4Comments

silvenon picture silvenon  Â·  4Comments