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

Programatic cancelling of a drag #9

Closed
alexreardon opened this issue Aug 10, 2017 · 5 comments
Closed

Programatic cancelling of a drag #9

alexreardon opened this issue Aug 10, 2017 · 5 comments

Comments

@alexreardon
Copy link
Collaborator

Once a drag has started there is no way to cancel it except through user input. There may be a scenario where the application wants to clear any current drag

@alexreardon
Copy link
Collaborator Author

alexreardon commented Feb 23, 2018

For now you can do this by triggering an 'escape' keydown event on the window

const triggerEscape = () => {
 const event = new window.KeyboardEvent('keydown', {
    bubbles: true,
    cancelable: true,
    keyCode: 27,
 });
 window.dispatchEvent(event);
}

triggerEscape();

@mheavenor
Copy link

mheavenor commented Mar 9, 2018

Hey @alexreardon,

I am having trouble using the above code snippet. In typescript, the interface for KeyboardEventInit (the type of the second argument in KeyboardEvent) does not contain the keyCode property. Even after creating the event I cant explicitly set the keyCode property as it is read only.

As per the MDN docs, keyCode is deprecated. Maybe the code should be changed so that the code or key property is checked on the event rather than keyCode.

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode

@alexreardon
Copy link
Collaborator Author

The code I listed is just a work around. You can trigger an escape key press however you like. While event.keyCode is deprecated it still works everywhere. Newer methods such as event.key do not have as wide support

@alexreardon
Copy link
Collaborator Author

This might be possible as a part of work relating to #1225

@alexreardon
Copy link
Collaborator Author

This will ship in #1317 as a part of #162

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

No branches or pull requests

2 participants