The Javascript onmouseup
event is not triggered if the mouse button is released outside the element on which onmousedown
has been triggered.
This causes a drag&drop bug in JQuery UI: A JQuery draggable element does not stop dragging when mouse button is released outside of its container (because the element will stop moving when reaching it's parent boundaries). Steps to reproduce:
- Go to http://jqueryui.com/draggable/.
- Drag the draggable downward until the mouse has left the surrounding container
- Release mouse button (no mouse button is pressed at this point)
- Move mouse back into container
- And the draggable is still being dragged. I would expect the dragging to have stopped as soon as I released the mouse button - no matter where it is released.
I see that behavior in latest Chrome and IE.
Is there any work-around?
I know that we could stop dragging the container on mouseout
or mouseleave
, but I would like to keep dragging, even if I am outside the parent container, much like in google maps (no matter, where you release the mouse, it always stops dragging the map).
You can have your mousedown element "capture" the pointer. Then it would always receive the mouseup event. In React this could look like this:
And here is an implementation using "plain vanilla" html + javascript: