diff --git a/packages/field/index.js b/packages/field/index.js index e017fa5f2..4e4eb6b65 100644 --- a/packages/field/index.js +++ b/packages/field/index.js @@ -2,6 +2,7 @@ import Icon from '../icon'; import Cell from '../cell'; import { cellProps } from '../cell/shared'; import { use, isObj, isDef, isIOS } from '../utils'; +import { preventDefault } from '../utils/event'; import { getRootScrollTop } from '../utils/scroll'; import { isNumber } from '../utils/validate/number'; @@ -137,7 +138,7 @@ export default sfc({ }, onClear(event) { - event.preventDefault(); + preventDefault(event); this.$emit('input', ''); this.$emit('clear'); }, @@ -148,8 +149,9 @@ export default sfc({ const allowPoint = String(this.value).indexOf('.') === -1; const isValidKey = (keyCode >= 48 && keyCode <= 57) || (keyCode === 46 && allowPoint) || keyCode === 45; + if (!isValidKey) { - event.preventDefault(); + preventDefault(event); } } diff --git a/packages/image-preview/ImagePreview.js b/packages/image-preview/ImagePreview.js index cb061dae6..14102ea02 100644 --- a/packages/image-preview/ImagePreview.js +++ b/packages/image-preview/ImagePreview.js @@ -1,4 +1,5 @@ import { use, range } from '../utils'; +import { preventDefault } from '../utils/event'; import { PopupMixin } from '../mixins/popup'; import { TouchMixin } from '../mixins/touch'; import Swipe from '../swipe'; @@ -98,7 +99,7 @@ export default sfc({ }, onWrapperTouchEnd(event) { - event.preventDefault(); + preventDefault(event); const deltaTime = new Date() - this.touchStartTime; const { offsetX = 0, offsetY = 0 } = this.$refs.swipe || {}; @@ -154,8 +155,7 @@ export default sfc({ onTouchMove(event) { const { touches } = event; if (this.moving || this.zooming) { - event.preventDefault(); - event.stopPropagation(); + preventDefault(event, true); } if (this.moving) { @@ -199,8 +199,7 @@ export default sfc({ } if (stopPropagation) { - event.preventDefault(); - event.stopPropagation(); + preventDefault(event, true); } } }, diff --git a/packages/mixins/popup/index.js b/packages/mixins/popup/index.js index b772e1e4a..076b1cf6c 100644 --- a/packages/mixins/popup/index.js +++ b/packages/mixins/popup/index.js @@ -1,6 +1,6 @@ import { context } from './context'; import { TouchMixin } from '../touch'; -import { on, off } from '../../utils/event'; +import { on, off, preventDefault } from '../../utils/event'; import { openOverlay, closeOverlay, updateOverlay } from './overlay'; import { getScrollEventTarget } from '../../utils/scroll'; @@ -176,13 +176,11 @@ export const PopupMixin = { /* istanbul ignore next */ if ( - event.cancelable && status !== '11' && this.direction === 'vertical' && !(parseInt(status, 2) & parseInt(direction, 2)) ) { - event.preventDefault(); - event.stopPropagation(); + preventDefault(event, true); } }, diff --git a/packages/number-keyboard/Key.js b/packages/number-keyboard/Key.js index ef201ce61..01817c18e 100644 --- a/packages/number-keyboard/Key.js +++ b/packages/number-keyboard/Key.js @@ -1,4 +1,5 @@ import { use } from '../utils'; +import { preventDefault } from '../utils/event'; const [sfc, bem] = use('key'); @@ -29,8 +30,7 @@ export default sfc({ }, onBlur(event) { - event.preventDefault(); - event.stopPropagation(); + preventDefault(event, true); this.active = false; } }, diff --git a/packages/number-keyboard/index.js b/packages/number-keyboard/index.js index 88b219927..66b25dfcb 100644 --- a/packages/number-keyboard/index.js +++ b/packages/number-keyboard/index.js @@ -1,5 +1,5 @@ import { use } from '../utils'; -import { stop } from '../utils/event'; +import { stopPropagation } from '../utils/event'; import Key from './Key'; const [sfc, bem, t] = use('number-keyboard'); @@ -145,7 +145,7 @@ export default sfc({ vShow={this.show} style={{ zIndex: this.zIndex }} class={bem([theme, { 'safe-area-inset-bottom': this.safeAreaInsetBottom }])} - onTouchstart={stop} + onTouchstart={stopPropagation} onAnimationend={this.onAnimationEnd} onWebkitAnimationEnd={this.onAnimationEnd} > diff --git a/packages/overlay/index.tsx b/packages/overlay/index.tsx index 02cedf261..d30549f92 100644 --- a/packages/overlay/index.tsx +++ b/packages/overlay/index.tsx @@ -1,5 +1,6 @@ import { use } from '../utils'; import { inherit } from '../utils/functional'; +import { preventDefault } from '../utils/event'; // Types import { CreateElement, RenderContext } from 'vue/types'; @@ -36,8 +37,7 @@ function Overlay( style={style} class={[bem(), props.className]} onTouchmove={(event: TouchEvent) => { - event.preventDefault(); - event.stopPropagation(); + preventDefault(event, true); }} {...inherit(ctx, true)} /> diff --git a/packages/picker/PickerColumn.js b/packages/picker/PickerColumn.js index 353b154a5..382482f4a 100644 --- a/packages/picker/PickerColumn.js +++ b/packages/picker/PickerColumn.js @@ -1,5 +1,6 @@ import { deepClone } from '../utils/deep-clone'; import { use, isObj, range } from '../utils'; +import { preventDefault } from '../utils/event'; const DEFAULT_DURATION = 200; const [sfc, bem] = use('picker-column'); @@ -55,7 +56,7 @@ export default sfc({ }, onTouchMove(event) { - event.preventDefault(); + preventDefault(event); const deltaY = event.touches[0].clientY - this.startY; this.offset = range( this.startOffset + deltaY, diff --git a/packages/picker/index.js b/packages/picker/index.js index 731d0a5e1..7462c8156 100644 --- a/packages/picker/index.js +++ b/packages/picker/index.js @@ -1,5 +1,5 @@ import { use } from '../utils'; -import { prevent } from '../utils/event'; +import { preventDefault } from '../utils/event'; import { deepClone } from '../utils/deep-clone'; import { pickerProps } from './shared'; import Loading from '../loading'; @@ -177,7 +177,7 @@ export default sfc({ ) : ( h() )} -