Add impassive event modifier !passive
wangf1978 opened this issue · 2 comments
What problem does this feature solve?
In modern browsers, for some events, for example, wheel, touchstart and so on, if you want to add event listener to it, passive option with true or false need to be specified explicitly, otherwise browser will report some warnings like as:
In some scenario, this default behavior has to be prevented like as using the below code
<div v-if="img.focused == true && img.selected == false" class="photo_selection"
v-on:click="on_toggle_photo_checkbox(img, true, $event, imgTypePos + start_list_idx_in_vw)"
v-on:touchstart.prevent="on_toggle_photo_checkbox(img, true, $event, imgTypePos + start_list_idx_in_vw)">
but there is no way to specify passive: false to vue runtime-dom
https://github.com/vuejs/core/tree/main/packages/runtime-dom/src/modules)/events.ts
tons of warnings will be reported by the latest chrome and edge console
What does the proposed API look like?
https://github.com/vuejs/core/tree/main/packages/runtime-dom/src/modules)/events.ts
@[touchstart|wheel....].prevent.!passive
v-on:[touchstart|wheel....].prevent.!passive
const optionsModifierRE = /(?:Once|Passive|!Passive|Capture)$/
function parseName(name: string): [string, EventListenerOptions | undefined] {
let options: EventListenerOptions | undefined
if (optionsModifierRE.test(name)) {
options = {}
let m
while ((m = name.match(optionsModifierRE))) {
name = name.slice(0, name.length - m[0].length)
if (m[0][0] === '!')
;(options as any)[m[0].slice(1).toLowerCase()] = false
else
;(options as any)[m[0].toLowerCase()] = true
}
}
const event = name[2] === ':' ? name.slice(3) : hyphenate(name.slice(2))
return [event, options]
}
If you're referring to https://chromestatus.com/feature/5093566007214080 it sounds like it only applies when touchstart is added to the document, not when its added to a div. I've been trying to come up with a reproduction with a vue div that will trigger that warning, but haven't been able to. Do you have a reproduction e.g. sfc.vuejs.org ? Here's what I tried:
When I add touchstart
to the document, .cancelable
is false (meaning it's passive). But touchstart
on the div has .cancelable
true (meaning it's active)