-
Notifications
You must be signed in to change notification settings - Fork 295
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
Allow custom activation behavior to be added to an event #1320
Comments
In the specification activation behavior is associated with the event target, not the event. And it's very much tied to (This reminds me a bit of the "event group" concept in https://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Event-groups.) cc @smaug---- @rniwa |
Gecko has a variant of "event group", so called system event group, and listeners in that are called after the normal DOM event dispatch. (And it was also exposed to XBL) EventTargets could perhaps have some callback for activation behavior, and that could either override the native activation behavior, or other option is to control that using .preventDefault() if the callback gets the event as param. Certain cases like nesting inside an anchor element might complicate things - which all activation behaviors should be triggered? |
Yeah, I like that idea.
I don't think that works, because you want the activation behaviour to not-run if the default is prevented. |
For input fields and forms, we have "change" and "submit" events as happening after processing a lower level event like click, keydown, keyup, Enter, drag-and-drop, clipboard paste, etc. What if anchor elements emitted an event like "navigate" or "activate" which wouldn't be cancellable, to happen when performing the action, regardless of how it was triggered and whether it was cancelled?
|
"submit" is another problem event here, as it can be cancelled. |
@jakearchibald I see. Another example is I suspect we would see people use I see this come up a fair bit in developer code at Wikimedia, where event+timeout is used as a way to plug into something at a point where there is no DOM event or app-provided callback (yet). Even more so in asynchronous code, where the synchronous assumptions by event handlers (apart from eg. in Service Workers), would be insufficient anyway. Because For simple one-to-one and synchronous use cases, If so, I wonder if the the platform should follow that pattern too? We have this for The reason I'm saying all this, is because I think re-using the event system is easier to learn, easier to extend and adopt for applications with their own events, scales to async behaviours, and perhaps also easier to integrate into frameworks and abstractions that already understand events. I also see value in being able to listen to these through propagation, without needing to attach a synchronous listener to (one or more) possible earlier events that lead to the activation. Think about scroll events and the jank they caused. In other words |
What problem are you trying to solve?
I want to add activation behavior to the above button, such as "when this button is clicked, toggle this checkbox". As expected on the platform, I don't want this action to happen if a listener calls
event.preventDefault()
.What solutions exist today?
This isn't great because the default may be prevented by a listener further along the path.
This isn't great because the effect may happen a frame later (
rAF
isn't a reliable solution here due to whatwg/html#10113). It's also observably async:Other techniques, like adding listeners to
window
may be missed due tostopPropagation()
, and may still be 'beaten' by another listener.How would you solve it?
Something like:
Anything else?
No response
The text was updated successfully, but these errors were encountered: