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

Bug when re-rendering occurs while mouse is pressed #73

Open
aduggleby opened this issue Oct 7, 2016 · 3 comments
Open

Bug when re-rendering occurs while mouse is pressed #73

aduggleby opened this issue Oct 7, 2016 · 3 comments

Comments

@aduggleby
Copy link
Contributor

Summary:
We use SortableContainer in dynamic mode. When the mouse is pressed (so onMouseDown has triggered, but onMouseUp has not yet) and a render happens then draggingIndex is set, the render will create a dragging element but will then not delete it once mouse is released again.

Reproduction:
This behaviour can be reproduced with the demo:
http://jasonslyvia.github.io/react-anything-sortable/demo/#/dynamic

Simply open debugging tools, run this statement in the console:

setTimeout(function(){ document.querySelectorAll("[data-reactid='.0.1.1.0']")[0].click() },5000)

(which will trigger the button on the page after 5 seconds).

Now click and hold the second element (titled "225") without moving the mouse (so onMouseMove does not trigger) and wait for the timer to expire. In the DOM Viewer you can see that the render happens once the button is pressed, the element "_dragging" appears but does not disappear when you release the mouse.

In the demo the placeholder with the title "225" stays over the first element.

See resulting screenshot here:
image

See resulting DOM here:
image

Fix:
We have fixed this issue for us by checking for the isDragging state in the renderItems method, as follows:

      if (index === this._draggingIndex && this.state.isDragging) {
        draggingItem = this.renderDraggingItem(item);
      }
@jasonslyvia
Copy link
Owner

Awesome! Really appreciate your effort @aduggleby

@aduggleby
Copy link
Contributor Author

hi, just checking in if my PR will be accepted for this

@jasonslyvia
Copy link
Owner

I'm really sorry, work has been busy these days, will merge ASAP.

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

No branches or pull requests

2 participants