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

fix(Picker): avoid Vue 2.6 event bubble issues by manually binding event #5345

Merged
merged 1 commit into from Dec 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/picker/PickerColumn.js
@@ -1,7 +1,7 @@
import { deepClone } from '../utils/deep-clone';
import { createNamespace, isObj } from '../utils';
import { range } from '../utils/format/number';
import { preventDefault } from '../utils/dom/event';
import { on, preventDefault } from '../utils/dom/event';
import { TouchMixin } from '../mixins/touch';

const DEFAULT_DURATION = 200;
Expand Down Expand Up @@ -60,6 +60,15 @@ export default createComponent({
this.setIndex(this.currentIndex);
},

mounted() {
// avoid Vue 2.6 event bubble issues by manually binding events
// https://github.com/youzan/vant/issues/3015
on(this.$el, 'touchstart', this.onTouchStart);
on(this.$el, 'touchmove', this.onTouchMove);
on(this.$el, 'touchend', this.onTouchEnd);
on(this.$el, 'touchcancel', this.onTouchEnd);
},

destroyed() {
const { children } = this.$parent;

Expand Down Expand Up @@ -127,7 +136,8 @@ export default createComponent({
const distance = this.offset - this.momentumOffset;
const duration = Date.now() - this.touchStartTime;
const allowMomentum =
duration < MOMENTUM_LIMIT_TIME && Math.abs(distance) > MOMENTUM_LIMIT_DISTANCE;
duration < MOMENTUM_LIMIT_TIME &&
Math.abs(distance) > MOMENTUM_LIMIT_DISTANCE;

if (allowMomentum) {
this.momentum(distance, duration);
Expand Down Expand Up @@ -166,7 +176,9 @@ export default createComponent({
},

getOptionText(option) {
return isObj(option) && this.valueKey in option ? option[this.valueKey] : option;
return isObj(option) && this.valueKey in option
? option[this.valueKey]
: option;
},

setIndex(index, userAction) {
Expand Down Expand Up @@ -279,13 +291,7 @@ export default createComponent({
};

return (
<div
class={[bem(), this.className]}
onTouchstart={this.onTouchStart}
onTouchmove={this.onTouchMove}
onTouchend={this.onTouchEnd}
onTouchcancel={this.onTouchEnd}
>
<div class={[bem(), this.className]}>
<ul
ref="wrapper"
style={wrapperStyle}
Expand Down