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

improvement(components): @touchstart @touchmove @wheel add passive #16741

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion packages/components/color-picker/src/utils/draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ export function draggable(element: HTMLElement, options: DraggableOptions) {
}

element.addEventListener('mousedown', downFn)
element.addEventListener('touchstart', downFn)
element.addEventListener('touchstart', downFn, { passive: false })
}
1 change: 0 additions & 1 deletion packages/components/slider/src/button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@mouseenter="handleMouseEnter"
@mouseleave="handleMouseLeave"
@mousedown="onButtonDown"
@touchstart="onButtonDown"
@focus="handleMouseEnter"
@blur="handleMouseLeave"
@keydown="onKeyDown"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, inject, nextTick, ref, watch } from 'vue'
import { debounce } from 'lodash-unified'
import { useEventListener } from '@vueuse/core'
import { EVENT_CODE, UPDATE_MODEL_EVENT } from '@element-plus/constants'
import { sliderContextKey } from '../constants'

Expand Down Expand Up @@ -273,6 +274,8 @@ export const useSliderButton = (
}
)

useEventListener(button, 'touchstart', onButtonDown, { passive: false })

return {
disabled,
button,
Expand Down
16 changes: 12 additions & 4 deletions packages/components/slider/src/slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
:aria-labelledby="
range && isLabeledByFormItem ? elFormItem?.labelId : undefined
"
@touchstart="onSliderWrapperPrevent"
@touchmove="onSliderWrapperPrevent"
>
<div
ref="slider"
Expand All @@ -20,7 +18,7 @@
]"
:style="runwayStyle"
@mousedown="onSliderDown"
@touchstart="onSliderDown"
@touchstart.passive="onSliderDown"
>
<div :class="ns.e('bar')" :style="barStyle" />
<slider-button
Expand Down Expand Up @@ -108,7 +106,8 @@
</template>

<script lang="ts" setup>
import { computed, provide, reactive, toRefs } from 'vue'
import { computed, onMounted, provide, reactive, toRefs } from 'vue'
import { useEventListener } from '@vueuse/core'
import ElInputNumber from '@element-plus/components/input-number'
import { useFormItemInputId, useFormSize } from '@element-plus/components/form'
import { useDeprecated, useLocale, useNamespace } from '@element-plus/hooks'
Expand Down Expand Up @@ -235,6 +234,15 @@ const updateDragging = (val: boolean) => {
initData.dragging = val
}

onMounted(() => {
useEventListener(sliderWrapper, 'touchstart', onSliderWrapperPrevent, {
passive: false,
})
useEventListener(sliderWrapper, 'touchmove', onSliderWrapperPrevent, {
passive: false,
})
})

btea marked this conversation as resolved.
Show resolved Hide resolved
provide(sliderContextKey, {
...toRefs(props),
sliderSize,
Expand Down
6 changes: 5 additions & 1 deletion packages/components/virtual-list/src/builders/build-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
resolveDynamicComponent,
unref,
} from 'vue'
import { useEventListener } from '@vueuse/core'
import {
getScrollBarWidth,
hasOwn,
Expand Down Expand Up @@ -355,6 +356,10 @@ const createGrid = ({
}
)

useEventListener(windowRef, 'wheel', onWheel, {
passive: false,
})

const scrollTo = ({
scrollLeft = states.value.scrollLeft,
scrollTop = states.value.scrollTop,
Expand Down Expand Up @@ -648,7 +653,6 @@ const createGrid = ({
class: props.className,
style: unref(windowStyle),
onScroll,
onWheel,
ref: windowRef,
},
!isString(Container) ? { default: () => Inner } : Inner
Expand Down
7 changes: 5 additions & 2 deletions packages/components/virtual-list/src/builders/build-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
resolveDynamicComponent,
unref,
} from 'vue'
import { useEventListener } from '@vueuse/core'
import { hasOwn, isClient, isNumber, isString } from '@element-plus/utils'
import { useNamespace } from '@element-plus/hooks'
import { useCache } from '../hooks/use-cache'
Expand Down Expand Up @@ -171,6 +172,10 @@ const createList = ({
}
)

useEventListener(windowRef, 'wheel', onWheel, {
passive: false,
})

const emitEvents = () => {
const { total } = props

Expand Down Expand Up @@ -458,7 +463,6 @@ const createList = ({
total,
onScroll,
onScrollbarScroll,
onWheel,
states,
useIsScrolling,
windowStyle,
Expand Down Expand Up @@ -518,7 +522,6 @@ const createList = ({
class: [ns.e('window'), className],
style: windowStyle,
onScroll,
onWheel,
ref: 'windowRef',
key: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const ScrollBar = defineComponent({
onselectstartStore = document.onselectstart
document.onselectstart = () => false

thumbEl.addEventListener('touchmove', onMouseMove)
thumbEl.addEventListener('touchmove', onMouseMove, { passive: true })
thumbEl.addEventListener('touchend', onMouseUp)
}

Expand Down