Open hirasso opened 1 month ago
@ekwoka thank you for approving this.
While I'm mostly against the idea of someone actually preventing default on any of these events
Sure... but I would still prefer if Alpine.js would make all native event listener options available instead of deciding for users what's good for them 🙂
I'd hope that the opt-in shape of the modifier .passive.false
is a good-enough safeguard for not using this unintentionally.
An alternative would be no-passive
...not sure if that's better.
An alternative would be
no-passive
...not sure if that's better.
Added naming to the questions section in the PR description.
As discussed in #4403 , this PR adds a way to set event listeners to
{passive: false}
:Use case
In horizontal sliders, it's necessary to stop vertical scrolling of the viewport when flicking through the slides. Registering a non-passive touchmove handler makes this possible:
touchstart
event and save the x-coordinatetouchmove
event with{passive: false}
and check if the x-coordinate is more than 3 (or whatever) pixels away from thetouchstart
coordinate. If so, disable vertical scrolling by callinge.preventDefault()
Checks
Questions
{passive: true}
usingx-on.passive.true
but wasn't able to get it to work. The handler in the cypress test just didn't fire at all (defaultPrevented
stayednull
, even after the click). But then I thought why even providepassive.true
if that's the current behavior of.passive
already?on.js
, would we need to add"false"
to the list inisListeningForASpecificKeyThatHasntBeenPressed
? Not sure what the function does exactly..passive.false
, as there are no other options as for example in the.transition
modifier?.no-passive
as suggested by @ekwoka ?.passive-false
?true
asfalse
is possible?