Skip to content

Conversation

@chunksnbits
Copy link

…gistration to mousedown event handler. Sets mouseup listener onto document.

Hi,
I really loved your approach for the tiny draggable, but found it was lacking one key feature I needed to make it work for my application. I created a fork for this and thought maybe you'd be interested in some of the changes I made:

  • I added a simple callback, that allows to cancel the event. For me that made it possible a) to add a class indicating the state (for styling reasons) and b) cancel the event, if the user attempted to drag the element out of bounds.
  • I register the mouseup event to the document instead of the handle. This makes it possible to end the dragging even if you happen to not have the mouse above the handle when the event occurs (e.g., because you moved the mouse off-bounds)
  • I deregister both drag and mouseup listener specifically in order not to interfere with other handlers that might have been attached.

Those changes increase the size a tiny bit, but add some functionality with just a few more lines.
Feel free to accept the request or cherry pick anything you like.

Cheers,
Daniel

…gistration to mousedown event handler. Sets mouseup listener onto document.
@SimonSteinberger
Copy link

I think that's sounds interesting. I'll take a closer look soon. Thanks 👍

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

Successfully merging this pull request may close these issues.

2 participants