-
Notifications
You must be signed in to change notification settings - Fork 262
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
修改picker组件issue #2360
base: next
Are you sure you want to change the base?
修改picker组件issue #2360
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -98,7 +98,7 @@ const InternalPicker: ForwardRefRenderFunction< | |||||||||||||||||||||
defaultValue: [...defaultValue], | ||||||||||||||||||||||
finalValue: [...defaultValue], | ||||||||||||||||||||||
onChange: (val: (string | number)[]) => { | ||||||||||||||||||||||
props.onConfirm?.(setSelectedOptions(), val) | ||||||||||||||||||||||
!val && props.onConfirm?.(setSelectedOptions(), val) | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
const [innerVisible, setInnerVisible] = usePropsValue<boolean>({ | ||||||||||||||||||||||
|
@@ -197,7 +197,11 @@ const InternalPicker: ForwardRefRenderFunction< | |||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||
setInnerValue(innerValue !== selectedValue ? selectedValue : innerValue) | ||||||||||||||||||||||
// 此hook的作用是‘如果内部选中值与用户选中值不同则把内部值置用户选中值’保证用户打开选项时选中的是选择的值。 | ||||||||||||||||||||||
// 但是当用户并没有进行确认选择,则不需要进行修改innerValue,否则会出现 issue#2290的问题 | ||||||||||||||||||||||
if (innerValue !== selectedValue && selectedValue.length > 0) { | ||||||||||||||||||||||
setInnerValue(selectedValue) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+200
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处的逻辑处理可能会导致不必要的状态更新,建议仅在 - if (innerValue !== selectedValue && selectedValue.length > 0) {
+ if (!isEqual(innerValue, selectedValue) && selectedValue.length > 0) {
setInnerValue(selectedValue)
} Committable suggestion
Suggested change
|
||||||||||||||||||||||
}, [innerVisible, selectedValue]) | ||||||||||||||||||||||
|
||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||
|
@@ -206,11 +210,6 @@ const InternalPicker: ForwardRefRenderFunction< | |||||||||||||||||||||
} | ||||||||||||||||||||||
}, [options, innerVisible]) | ||||||||||||||||||||||
|
||||||||||||||||||||||
// 选中值进行修改 | ||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||
onChange && onChange(setSelectedOptions(), innerValue, columnIndex) | ||||||||||||||||||||||
}, [innerValue, columnsList]) | ||||||||||||||||||||||
|
||||||||||||||||||||||
const setSelectedOptions = () => { | ||||||||||||||||||||||
const options: PickerOption[] = [] | ||||||||||||||||||||||
let currOptions = [] | ||||||||||||||||||||||
|
@@ -251,6 +250,8 @@ const InternalPicker: ForwardRefRenderFunction< | |||||||||||||||||||||
] | ||||||||||||||||||||||
setInnerValue(combineResult) | ||||||||||||||||||||||
setColumnsList(normalListData(combineResult) as PickerOption[][]) | ||||||||||||||||||||||
|
||||||||||||||||||||||
onChange && onChange(setSelectedOptions(), combineResult, columnIndex) | ||||||||||||||||||||||
Comment on lines
+253
to
+254
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议使用可选链操作符来简化代码。 - onChange && onChange(setSelectedOptions(), combineResult, columnIndex)
+ onChange?.(setSelectedOptions(), combineResult, columnIndex) Also applies to: 262-264 |
||||||||||||||||||||||
} else { | ||||||||||||||||||||||
setInnerValue((data: (number | string)[]) => { | ||||||||||||||||||||||
const cdata: (number | string)[] = [...data] | ||||||||||||||||||||||
|
@@ -260,6 +261,7 @@ const InternalPicker: ForwardRefRenderFunction< | |||||||||||||||||||||
) | ||||||||||||||||||||||
? columnOptions.value | ||||||||||||||||||||||
: '' | ||||||||||||||||||||||
onChange && onChange(setSelectedOptions(), cdata, columnIndex) | ||||||||||||||||||||||
return cdata | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码逻辑存在潜在问题。当
val
为undefined
或null
时,onConfirm
事件仍会被调用,这可能不是预期行为。Committable suggestion