-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Improve how raw input events are handled #375
Comments
WIP User events
Prior knowledgeThis page assumes a working knowledge of DOM events. For a good introduction to DOM events see: Safe event bindingsWithout needing going into all the details below, here are the safest event handlers to build on top of
You may need to provide your event handlers with information from You are welcome to add other event handlers but you may be more reliant on General rulesEvent preventionWhen we use an input event as part of a drag and drop interaction we generally call Some event handlers we add on the drag handle itself (see In order to know if we have already used the event for the purpose of drag and drop you need to check the So let's say you want to add a window window.addEventListener('click', (event: MouseEvent) => {
// event has already been used for drag and drop
if (event.defaultPrevented) {
return;
}
doMyCoolThing();
}); Direct and indirect eventsSome user events directly cause actions: such as a Mouse dragging 🐭Initial
|
Hi @alexreardon I was able to hiJAck the resize event by using Would this be something we would like to see as a boolean flag? Thanks |
Right now we put a fair amount of effort into preventing click events from being published after a drag.
As a part of implementing a muti-drag pattern (#10) we need to be consistent with how we are processing events (
mousedown
,mouseup
,click
, and so on). Right now we sometimes block these events (usingevent.stopPropogation()
) and prevent their default behaviour (usingevent.preventDefault()
), sometimes let them pass through. This can result in unmatched event pairs.For example, in a mouse drag we stop the mousedown event being propogated. However, if they do not start a drag we allow the mouseup event to go through. The result of this is that consumers can get a mouseup without a proceeding mousedown event which can be confusing. In that situation we could also block the mousedown even if the user was not dragging but then a click will be published which might be unexpected given that there was no previous mouseup and mousedown event. There are other scenarios where we block on events in a pair (eg only block one of keydown and keyup).
Proposed solution
Rather than conditionally stopping events with event.stopPropagation() we should publish every event and only use event.preventDefault() on events we are controlling. This way consumers can get every event as well as knowing if they should use it or not through the event.defaultPrevented property.
The text was updated successfully, but these errors were encountered: