From 020f13ad360b2b04ccd0b5a52f04f08567a669dd Mon Sep 17 00:00:00 2001 From: Ethan Zhao Date: Mon, 23 Dec 2024 22:02:44 +0800 Subject: [PATCH] fix(Slider): slider btn cannot drag in mobile device (#4860) * fix(Slider): slider btn cannot drag in mobile device * fix(Slider): slider btn cannot drag in mobile device --------- Co-authored-by: Ethan Zhao --- src/slider/slider-button.tsx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/slider/slider-button.tsx b/src/slider/slider-button.tsx index 38a955302e..d1677745d1 100644 --- a/src/slider/slider-button.tsx +++ b/src/slider/slider-button.tsx @@ -1,21 +1,21 @@ import { - PropType, - defineComponent, ComponentPublicInstance, - ref, + PropType, computed, - reactive, + defineComponent, + inject, nextTick, + reactive, + ref, watchEffect, - inject, } from 'vue'; import TTooltip from '../tooltip/index'; import { TdSliderProps } from './type'; +import isFunction from 'lodash/isFunction'; import { usePrefixClass } from '../hooks/useConfig'; import { useSliderTooltip } from './hooks/useSliderTooltip'; import { sliderPropsInjectKey } from './util/constants'; -import isFunction from 'lodash/isFunction'; export default defineComponent({ name: 'TSliderButton', @@ -147,10 +147,16 @@ export default defineComponent({ } let diff = 0; const parentSliderSize = parentProps.sliderSize; + const { type } = event; + let { clientY, clientX } = event as MouseEvent; + if (type === 'touchmove') { + const touch = (event as TouchEvent).touches; + [clientY, clientX] = [touch[0].clientY, touch[0].clientX]; + } if (props.vertical) { - diff = slideButtonProps.startY - (event as MouseEvent).clientY; + diff = slideButtonProps.startY - clientY; } else { - diff = (event as MouseEvent).clientX - slideButtonProps.startX; + diff = clientX - slideButtonProps.startX; } diff = (diff / parentSliderSize) * 100; slideButtonProps.newPos = slideButtonProps.startPos + diff;