Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support conditional binding for listeners like v-touch-pan #6083

Closed
gruppler opened this issue Jan 12, 2020 · 4 comments
Closed

Support conditional binding for listeners like v-touch-pan #6083

gruppler opened this issue Jan 12, 2020 · 4 comments

Comments

@gruppler
Copy link

gruppler commented Jan 12, 2020

Is your feature request related to a problem? Please describe.
I want to conditionally capture swiping, but currently there doesn't seem to be a way to do this. To be clear, I don't want to capture/prevent touch-starts unless my handler is enabled, because this interferes with scrolling.

Describe the solution you'd like
If a handler is null, silently abort and unbind the listener. If the handler changes from null to a function, rebind the listener.

Describe alternatives you've considered
I can't think of any other way to accomplish this. Currently, I'm using the following code, which works but produces errors ("ctx.handler is not a function"):
v-touch-pan.prevent.mouse="board3D ? rotateBoard : null"

Additional context
Vue 2.6 allows for conditional event binding.

@metalsadman
Copy link
Member

metalsadman commented Jan 13, 2020

@gruppler because the directive expects a handler, you can just supply a noop function. ie. v-touch-pan.prevent.mouse="condition ? yourHandler : () => {}"

https://codepen.io/metalsadman/pen/ExaRKyJ?editable=true&editors=111

@gruppler
Copy link
Author

The problem with that solution is it still captures the event even when inactive, preventing scrolling.

pdanpdan added a commit to pdanpdan/quasar that referenced this issue Jan 14, 2020
pdanpdan added a commit to pdanpdan/quasar that referenced this issue Jan 14, 2020
@rstoenescu
Copy link
Member

Starting with future "quasar" v1.7.2, if the handler is a Function, it'll do something with it, otherwise it's gonna be equivalent to not having the touch directive(s) attached.

So this will be perfectly valid:
v-touch-pan.prevent.mouse="condition ? yourHandler : void 0"

Again, if handler is not a Function, then it won't interfere with ANY events.

@gruppler
Copy link
Author

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants