Skip to content

Commit

Permalink
fix: 修改onChange触发时机,解决第一次打开就触发onChange且传值错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
songjiaming committed Jun 18, 2024
1 parent b7116dd commit 6aba177
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/packages/picker/picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ const InternalPicker: ForwardRefRenderFunction<
}
}, [options, innerVisible])

// 选中值进行修改
useEffect(() => {
onChange && onChange(setSelectedOptions(), innerValue, columnIndex)
}, [innerValue, columnsList])

const setSelectedOptions = () => {
const options: PickerOption[] = []
let currOptions = []
Expand Down Expand Up @@ -251,6 +246,8 @@ const InternalPicker: ForwardRefRenderFunction<
]
setInnerValue(combineResult)
setColumnsList(normalListData(combineResult) as PickerOption[][])

onChange && onChange(setSelectedOptions(), combineResult, columnIndex)
} else {
setInnerValue((data: (number | string)[]) => {
const cdata: (number | string)[] = [...data]
Expand All @@ -260,6 +257,7 @@ const InternalPicker: ForwardRefRenderFunction<
)
? columnOptions.value
: ''
onChange && onChange(setSelectedOptions(), cdata, columnIndex)
return cdata
})
}
Expand Down

0 comments on commit 6aba177

Please sign in to comment.