Skip to content

Commit

Permalink
fix: value设置须晚于options (#246
Browse files Browse the repository at this point in the history
  • Loading branch information
kongjing@dian.so authored and kongjing@dian.so committed Jun 9, 2022
1 parent 792fa34 commit 92f17f0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/vantui-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"@vant/area-data": "^1.1.3",
"@vant/icons": "^1.7.1",
"core-js": "^3.15.2",
"preact": "^10.7.3",
"react": "^17.0.0",
"react-dom": "^17.0.0"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/vantui-demo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10609,6 +10609,11 @@ postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.2, postcss@^7.0.21, postcss@^7.0.2
picocolors "^0.2.1"
source-map "^0.6.1"

preact@^10.7.3:
version "10.7.3"
resolved "https://registry.npmmirror.com/preact/-/preact-10.7.3.tgz#f98c09a29cb8dbb22e5fc824a1edcc377fc42b5a"
integrity sha512-giqJXP8VbtA1tyGa3f1n9wiN7PrHtONrDyE3T+ifjr/tTkg+2N4d/6sjC9WyJKv8wM7rOYDveqy5ZoFmYlwo4w==

preferred-pm@^1.0.1:
version "1.0.1"
resolved "https://registry.npmmirror.com/preferred-pm/-/preferred-pm-1.0.1.tgz#539df37ce944b1b765ae944a8ba34a7e68694e8d"
Expand Down
2 changes: 1 addition & 1 deletion packages/vantui-doc/src/datetime-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Demo() {
minHour: 10,
maxHour: 20,
minDate: new Date(2009, 10, 1).getTime(),
maxDate: new Date(2011, 10, 1).getTime(),
maxDate: new Date(2031, 10, 1).getTime(),
currentDate: new Date().getTime(),
})

Expand Down
10 changes: 7 additions & 3 deletions packages/vantui/src/datetime-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useImperativeHandle,
ForwardedRef,
} from 'react'
import { nextTick } from '@tarojs/taro'
import {
IPickerInstance,
PickerChangeEvents,
Expand Down Expand Up @@ -222,14 +223,17 @@ export function DatetimePicker(
)
}
}
setInnerValue(value)
updateColumns(value)

nextTick(() => {
setInnerValue(value)
})

return new Promise((resolve) => {
setTimeout(() => {
nextTick(() => {
picker.setValues(values)
resolve(`${value}`)
}, 16)
})
})
},
[formatter, getPicker, type, updateColumns],
Expand Down
7 changes: 6 additions & 1 deletion packages/vantui/src/picker-column/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
memo,
} from 'react'
import { View, CustomWrapper } from '@tarojs/components'
import { nextTick } from '@tarojs/taro'
import * as utils from '../wxs/utils'
import { PickerColumnProps } from '../../types/picker-column'
import { range } from '../common/utils'
Expand Down Expand Up @@ -72,7 +73,11 @@ function Index(
if (index !== currentIndex) {
setCurrentIndex(index)
setOffset(offset)
if (onChange && userAction) onChange(curColIndex)
if (onChange && userAction) {
nextTick(() => {
onChange(curColIndex)
})
}
return
}
return setOffset(offset)
Expand Down
8 changes: 5 additions & 3 deletions packages/vantui/src/picker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable react-hooks/exhaustive-deps */
import {
useEffect,
useCallback,
useRef,
forwardRef,
useImperativeHandle,
useLayoutEffect,
} from 'react'
import { View } from '@tarojs/components'
import {
Expand Down Expand Up @@ -44,7 +44,7 @@ const Picker = forwardRef(function Index(
const children = useRef<Array<any>>([])
const handleIndex = useRef<number>(-1)

useEffect(
useLayoutEffect(
function () {
if (Array.isArray(children) && children.length) {
setColumns().catch(() => {})
Expand Down Expand Up @@ -158,7 +158,9 @@ const Picker = forwardRef(function Index(
}, [])

const getValues = useCallback(function () {
return children.current.map((child) => child.getValue())
return children.current.map((child) => {
return child.getValue()
})
}, [])

const getIndexes = useCallback(function () {
Expand Down

0 comments on commit 92f17f0

Please sign in to comment.