-
Notifications
You must be signed in to change notification settings - Fork 38
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
Merge events into "onnavigate" or "onfocusmove"? #32
Comments
You can already do that with 3 events, and the handler would look almost identical to the one you'd write for what you suggest.
vs
The only difference is in how you register them: ['navbeforefocus', 'navbeforescroll', 'navnotarget'].map(function(e) {
element.addEventListener(e, spatnavHandler);
}); vs element.addEventListener("spatnav", spatnavHandler); But I am not sure you'd generally want the same handle for all three.
No strong opinion here. I was trying to follow the pattern of UI-EVENTS which has a That said, I'm not super happy about the current names, so if we're not (strongly) violating existing conventions by not using "before" in the name, maybe the shorter the better. |
That's a good argument for combining them. Web devs usually prefer compact code. |
It is an argument to combine them IF the typical case is to catch them all with the same handler. I am not convinced it is. I am sure that I am biased in all sorts of ways, but most use cases I can think of need different handlers for the different events, in which case the current design makes more sense. If you think that wanting to catch them all in the same handler is typical, could you share some use cases for that? |
Let me present the lazy JS developer Lars. Lars writes excellent code. He thinks. So if the error handling is not really needed he rather leaves it out, to save some time. To Lars, Now if one "tell it all"-event, let's call it Another common use case would be debugging. Lars normally doesn't care about the error-like events. But, while trying to figure out what his app is doing wrong, he puts a breakpoint / a log print in his From implementors' perspective, in C++ or Rust, I'd rather just implement and write tests for When promoting this spec to vendors, it'd be easier. We can just say "You only need to implement |
What I am still not understanding in your scenario: what is Lars trying to do that benefits form him catching all events together? Sure, if his code should be handling all three (especially if it should handled all three the same way), then making it easier to handle all three (the same way) is better. But why should it? If you put it in abstract terms like this, the same argument could apply to having a single To me, the situation is the same here. If the typical use case calls for a single unified event handler for all 3 cases, then merging them can make sense. I do not believe it does. Happy to be proven wrong, but that calls for use cases (specific examples of things authors are trying to achieve by catching those events). You can also turn the argument on its head: if Lars doesn't think of what sounds like "error cases" to him, then he won't handle them when he first writes the code. Then on his 27 inch iMac, everything fits the screen without scrolling or overflow, so in his environment, all he ever gets is the |
Ah, right. I can't think of anything you can do with a "combo-event" but not with 3 separate events... However, if one event can carry the same info, I'd like to think that it means less work for us later on when implementing and testing this API. Lazy devs might appreciate that there's two less events to read up on and to handle. This is how I imagine the "combo-event" The API signals a failure by setting Here
Here
The event signals something like "the user tried to move focus, here's the result". With a usage/example pattern that shows how While null-checking is usually something we would like to avoid, the mouse*-family of events also set Is there anything we can do with 3 events that we cannot do with a combo-event? |
Personally, I'm so in favor of a new event that would be the most prefered way to override a default heuristic algorithm of the spatial navigation. In this thread, there seems two approaches:
In my eyes, It wouldn't different between them in terms of the functionality and would have some pros and cons for each ways according to the use cases. However I'm in favor of the single unified event type as the following analysis. 1. API design
The all existing event types could be classified as two categories above. In general, events of (1) are cancelable, but events of (2) are not. Our proposed events would be in the middle phase of (1) and (2), because when the navigate event is invoked, the navigate operation is partially executed(getting several contexts) but isn't yet completed(cancelable) after the user interaction. It needs a cautious approach so that our new API could be merged into the existing event design and mechanism. When I first see the three event types, the wording such as focus, scroll, notarget seems the results of the navigation. It might be triggered as the default results by user agent when user pushes a tab key or arrow keys. In addition, we would like to use these kinds of events to cancel the default and override a new operation. What the default operation of each events are described in its names of event type, would be a little weird in terms of the existing event mechanism. Regarding 2. Usage of the API |
Hi @hugoholgersson and @anawhj. Thanks for the feedback. I think there is two parts in your suggestion: 1) An event that just lets the author know that the user triggered spatnav, without caring about details about how the UA would handle it (scrolling vs focusing vs not finding the target)We can easily add a new event that does that. We can call it "navigate" or "beforenav" or "spatnav" something like that, and it would be fired before the first step of the spatial navigations steps (or maybe before the first step of the navigation steps), and would cancel the navigation if cancelled. This could be useful for example if a user wants to completely cancel the existing spatial navigation, and do something completely different instead. I am OK with this, and think it would be a good addition. It does not change implementation complexity much. 2) Merge the existing 3 events in 1 event, with the reason (focus/scroll/no-target) distinguished by a
|
I agree. I closed #33 because finding the container can be done in pure JS.
Yes, that's almost what I want... But I think such an event actually can carry enough details.
I realized, we don't actually need a reason-attribute... First, say we remove the That makes it easier to combine (The
|
As I mentioned above, both approaches seem almost equivalent in terms of the functionality. When an arrow key is pushed for spatial navigation, new events should be invoked with the status (scrolling, focus moving, none) and a cancelable option so that authors use the events for several purpose. (e.g. overriding the heuristic spatial navigation, handling some edge cases, etc.) The event could be invoked as a unified single type (e.g. spatnav or navigate) with an object of three status information ( To more easily understand the comparison between two approaches, I put some examples below where an author want to apply nav-rule and nav-loop (non-primitive features) in a container element's event handlers. 1. three types of event handlers ( function navbeforefocusHandler(event) {
nav-rule-execute();
}
function navnotargetHandler(event) {
nav-loop-execute();
}
container.addEventListener("navbeforefocus", navbeforefocusHandler);
container.addEventListener("navnotarget", navnotargetHandler); 2. a single unified event handler ( function spatnavHandler(event) {
switch (event.dataTransfer.type) {
case 'focus':
nav-rule-execute(); break;
case 'none':
nav-loop-execute(); break;
case 'scroll':
return;
}
}
container.addEventListener("spatnav", spatnavHandler); I think we could see Drag and Drop events' design to review spatnav events. |
I'm thinking fewer events give authors a chance to write tighter JavaScript: one handler for all of the navigation-related reactions.
When authors tweak their apps' navigation, I imagine debugging being easier if they only need to break and assert things in one event handler (not 3). We will enjoy the same convenience when writing web platform tests.
Proposal: Give
NavigationEvent
areason
oraction
attribute.From an implementor's perspective I see two advantages:
By the way, the event's name does not need to include before. That's already implicit from being cancelable, right?
The text was updated successfully, but these errors were encountered: