Skip to content

Commit

Permalink
fix: slider组件支付宝小程序点击事件参数兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
kongjing@dian.so authored and kongjing@dian.so committed Nov 1, 2022
1 parent 5235c47 commit b5812c5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/vantui/src/slider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect, useCallback, useRef } from 'react'
import { ITouchEvent, View } from '@tarojs/components'
import { nextTick } from '@tarojs/taro'
import * as utils from '../wxs/utils'
import { style } from '../wxs/style'
import { SliderProps } from '../../types/slider'
Expand Down Expand Up @@ -91,7 +92,9 @@ export function Slider(props: SliderProps) {
offsetX: Math.abs(touchState.deltaX),
offsetY: Math.abs(touchState.deltaY),
}
setTouchState(newTouchState)
nextTick(() => {
setTouchState(newTouchState)
})
return newTouchState
},
[touchState, resetTouchStatus],
Expand Down Expand Up @@ -175,7 +178,9 @@ export function Slider(props: SliderProps) {
onChange({ detail: value } as ITouchEvent)
}
if ((drag || end) && canIUseModel()) {
setValue(value)
nextTick(() => {
setValue(value)
})
}
},
[
Expand Down Expand Up @@ -283,15 +288,17 @@ export function Slider(props: SliderProps) {
if (disabled) return
getRect(null, `.van-slider${indexRef.current}`).then((rect: any) => {
let value =
(((event.target.x || event.clientX) - rect.left) / rect.width) *
(((event.detail.x || event.detail.clientX) - rect.left) /
rect.width) *
getRange() +
min
Number(min)

if (vertical) {
value =
(((event.target.y || event.clientY) - rect.top) / rect.height) *
(((event.detail.y || event.detail.clientY) - rect.top) /
rect.height) *
getRange() +
min
Number(min)
}

if (isRange(value_)) {
Expand Down

0 comments on commit b5812c5

Please sign in to comment.