4 ms·
I recently had this debate with my friend, who built this fun test to see how much latency was actually added by waiting for mouseUp: https://click-duration-tim
by seabass 2y ago
I recently had this debate with my friend, who built this fun test to see how much latency was actually added by waiting for mouseUp: https://click-duration-timer.vercel.app/ https://click-duration-timer.vercel.app/
I felt pretty strongly that I would hate triggering events on mouseDown because of how often I "cancel" an action mid-click. But I decided to add this userscript to my browser and live with it for a week:
let preventNextClick = false;
const interactiveElements = ['a', 'button', 'input', 'select', 'textarea'];
document.addEventListener('mousedown', (event) => {
if (event.metaKey) return; // allow cmd+click to bail
if (event.button !== 0) return; // handle left clicks only
// ignore all but a handful of elements
const tagName = event.target.tagName.toLowerCase();
if (!interactiveElements.includes(tagName)) return;
event.target.click();
// set a flag to prevent firing two click events
preventNextClick = true;
});
document.addEventListener('click', (event) => {
if (preventNextClick) {
event.stopImmediatePropagation();
event.preventDefault();
preventNextClick = false;
}
}, true); // use capture phase
This causes any of the interactive elements on a page to trigger their onClick action during the mouseDown phase rather than onMouseUp. It's probably not perfect, just a scrappy user script. But omg it is so much nicer to browse with this enabled. And I say that as a hater of the original idea with strong opinions.
So, if you want to have a slightly more informed opinion on the issue I suggest trying this or something like it out for a week! I can't go back to the way it was before. Everything is so snappy now.
I haven't (yet) found a case where I wished I had the mid-click cancelability I had before. I think that getting used to the idea of clicks being instant rewired my brain a bit to simply not rely on that behavior anymore.
- wodenokoto 2y agoHow does dragging work when mouse down is a click?
- seabass 2y agoThat's a great point. Dragging on any of the interactive elements currently fails. Building in the cmd+click option to bail out makes it possible, though.
- darthoctopus 2y agothanks for the script!