Re:A BBC navigation bar component broke depending on the ext...
by t43562 on Monday November 18, 2024 @11:56AM
(#42174292)
...because when they are 0 one can infer that the event came from a keypress rather than a mouse. They want to know this.
[ Parent
| on HN ]
Re:A BBC navigation bar component broke depending on the ext...
by shdon on Monday November 18, 2024 @12:08PM
(#42174436)
Then it would make a lot more sense to check event.pointerType == 'mouse' vs event.pointerType == '' (for keyboard)
Re:A BBC navigation bar component broke depending on the ext...
by jorams on Monday November 18, 2024 @01:22PM
(#42175287)
That does seem quite obviously better. Even when insisting on checking coordinates why use the coordinate system carried by the event that you have the least control over. Why not .pageX/.pageY, which can't trigger the failure case as long as you make sure the element isn't in the far top left.
Re:A BBC navigation bar component broke depending on the ext...
by G1N on Monday November 18, 2024 @12:47PM
(#42174868)
Based on the other replies here it seems like it's to differentiate taps vs mouse clicks, keyboard events in js don't have a screenX or screenY property (you can run this in your browser console on this HN post to confirm):
(() => {
const logEvent = event => console.log({
coords: [event.screenX, event.screenY],
type: event.type
});
const input = document.querySelector("textarea");
// use "keydown" instead of "keypress" to detect all keyboard input instead of just character producing input
input.addEventListener("keydown", logEvent);
input.addEventListener("click", logEvent);
})();
Type in or click on the reply text input and you'll see that the coords array is undefined for all keyboard events. I haven't tried this equivalent on a touch device however, so not sure how it's handled there.
Re:A BBC navigation bar component broke depending on the ext...
by hyperhopper on Monday November 18, 2024 @01:00PM
(#42175013)
This does not work when the mouse is actually at 0,0
Re:A BBC navigation bar component broke depending on the ext...
by xboxnolifes on Monday November 18, 2024 @01:42PM
(#42175496)
An imperfect solution for a situation that will practically never happen and have no noticeable downside.
Re:A BBC navigation bar component broke depending on the ext...
by noworriesnate on Monday November 18, 2024 @08:49PM
(#42179370)
It'll screw up UI tests
Re:A BBC navigation bar component broke depending on the ext...
by xboxnolifes on Monday November 18, 2024 @10:28PM
(#42179861)
Clearly not, otherwise this bug would have been found much sooner.