Add non-passive event modifier
See original GitHub issueWhat problem does this feature solve?
An event modifier to support passive events was added in #5132.
In the last couple of years, browsers have adopted the passive behavior by default for touchstart and touchmove events (reference). Thus, to be able to cancel one of these events by calling e.preventDefault(), you need to explicitly pass { passive: false } when adding the event listener.
With the current API this is impossible to achieve in a Vue template (as far as I can tell). You must manually add and remove the event listener in a component hook like so:
this.$refs.someElement.addEventListener('touchstart', this.start, { passive: false });
this.$refs.someElement.addEventListener('touchmove', this.move, { passive: false });
// later
this.$refs.someElement.removeEventListener('touchstart', this.start);
this.$refs.someElement.removeEventListener('touchmove', this.move);
What does the proposed API look like?
An event modifier that does the opposite of the passive event modifier, specifying the option as false instead of true.
Unsure of the naming - perhaps nonPassive, active, assertive, intentional.
<div
@touchstart.active="start"
@touchmove.active="move"
></div>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Events / Event modifiers • Svelte Tutorial
DOM event handlers can have modifiers that alter their behaviour. ... add it automatically where it's safe to do so); nonpassive — explicitly...
Read more >Consider marking event handler as 'passive' to make the page ...
Consider marking event handler as 'passive' to make the page more responsive. So I tried to add 'passive' to the listener like so....
Read more >7 Event Modifiers in Svelte You Must Know
7 Event Modifiers in Svelte You Must Know · 1. preventDefault · 2. stopPropagation · 3. passive · 4. nonpassive · 5. once...
Read more >Event Handling - Vue.js
The .passive modifier is typically used with touch event listeners for improving performance on mobile devices.
Read more >Event Modifiers | Vue.js: Understanding its Tools and Ecosystem
.prevent .capture .self .once .passive. You can also chain multiple modifiers ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

In
vue/src/core/vdom/helpers/update-listeners.js:22,normalizeEventalways returns an object with a setpassiveproperty.I’m not familiar with Vue’s source code, but does that mean that when the
.passivemodifier is not present, each event handler is always declared as active? This seems wrong in the light of browser’s changing the default for certain event types to be passive by default (see Improving scrolling performance with passive listeners). If.passiveis not present, I don’t expect event handlers to be marked as not passive.With regards to the feature request itself, I think “active” would be a natural choice here.
the
divRefwould be what links the elements, the events would be added/removed as soon as the elements are added/removed from the dom. (it will internally add a watcher ondivRefand when it changes, does what it needs to to add the event.again, I’ve had to guesstimate some of this, so just assumed most of it are refs/computed, but
unrefdoesn’t care if it’s a value/ref/computed, it will get the value regardless.