Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 204
feat: support option in onChange handler#589
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
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -34,6 +34,7 @@ import type { | ||
| DefaultValueType, | ||
| FieldNames, | ||
| LegacyDataNode, | ||
| DefaultOptionType, | ||
| } from './interface'; | ||
| export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = DataNode> | ||
| @@ -45,7 +46,11 @@ export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = | ||
| // >>> Value | ||
| value?: ValueType; | ||
| defaultValue?: ValueType; | ||
| onChange?: (value: ValueType, labelList: React.ReactNode[], extra: ChangeEventExtra) => void; | ||
| onChange?: ( | ||
| value: ValueType, | ||
| labelList: React.ReactNode[], | ||
| extra: ChangeEventExtra & { option?: DefaultOptionType }, | ||
| ) => void; | ||
| // >>> Search | ||
| searchValue?: string; | ||
| @@ -410,7 +415,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | ||
| const triggerChange = useRefFunc( | ||
| ( | ||
| newRawValues: SafeKey[], | ||
| extra: { triggerValue?: SafeKey; selected?: boolean }, | ||
| extra: { triggerValue?: SafeKey; selected?: boolean; nodes?: DefaultOptionType }, | ||
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. 🛠️ Refactor suggestion 确保类型一致性 为保持代码一致性,建议将 - option: extra.nodes,+ nodes: extra.nodes,Also applies to: 464-465 | ||
| source: SelectSource, | ||
| ) => { | ||
| const labeledValues = convert2LabelValues(newRawValues); | ||
| @@ -456,7 +461,8 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | ||
| // [Legacy] Always return as array contains label & value | ||
| preValue: rawLabeledValues, | ||
| triggerValue, | ||
| } as ChangeEventExtra; | ||
| option: extra.nodes, | ||
| } as ChangeEventExtra & { option?: DefaultOptionType }; | ||
| // [Legacy] Fill legacy data if user query. | ||
| // This is expansive that we only fill when user query | ||
| @@ -505,7 +511,11 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | ||
| // Never be falsy but keep it safe | ||
| if (!mergedMultiple) { | ||
| // Single mode always set value | ||
| triggerChange([selectedValue], { selected: true, triggerValue: selectedValue }, 'option'); | ||
| triggerChange( | ||
| [selectedValue], | ||
| { selected: true, triggerValue: selectedValue, nodes: node as DefaultOptionType }, | ||
| 'option', | ||
| ); | ||
| } else { | ||
| let newRawValues = selected | ||
| ? [...rawValues, selectedValue] | ||
| @@ -535,7 +545,11 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | ||
| ...checkedKeys.map(key => keyEntities[key as SafeKey].node[mergedFieldNames.value]), | ||
| ]; | ||
| } | ||
| triggerChange(newRawValues, { selected, triggerValue: selectedValue }, source || 'option'); | ||
| triggerChange( | ||
| newRawValues, | ||
| { selected, triggerValue: selectedValue, nodes: node as DefaultOptionType }, | ||
| source || 'option', | ||
| ); | ||
| } | ||
| // Trigger select event | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
🛠️ Refactor suggestion
建议重命名参数以提高代码清晰度
根据之前的评审意见,建议将
option重命名为nodes,因为在多选模式下这个命名更准确。这样可以让接口更清晰地表达其用途。Also applies to: 49-53