Skip to content

Commit

Permalink
fix: 修复 formItem onchange细节
Browse files Browse the repository at this point in the history
  • Loading branch information
honkinglin committed Jul 25, 2022
1 parent e53050f commit c4c5d1d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions src/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((props, ref) => {
{React.Children.map(children, (child, index) => {
if (!child) return null;

let onChangeFromProps = () => ({});
let onBlurFromProps = () => ({});
let ctrlKey = 'value';
if (React.isValidElement(child)) {
if (child.type === FormItem) {
Expand All @@ -392,12 +390,6 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((props, ref) => {
},
});
}
if (typeof child.props.onChange === 'function') {
onChangeFromProps = child.props.onChange;
}
if (typeof child.props.onBlur === 'function') {
onBlurFromProps = child.props.onBlur;
}
if (typeof child.type === 'object') {
ctrlKey = ctrlKeyMap.get(child.type) || 'value';
}
Expand All @@ -406,12 +398,12 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((props, ref) => {
...child.props,
[ctrlKey]: formValue,
onChange: (value: any, ...args: any[]) => {
onChangeFromProps.call(null, value, ...args);
updateFormValue(value);
child.props.onChange?.call?.(null, value, ...args);
},
onBlur: (value: any, ...args: any[]) => {
onBlurFromProps.call(null, value, ...args);
handleItemBlur();
child.props.onBlur?.call?.(null, value, ...args);
},
});
}
Expand Down

0 comments on commit c4c5d1d

Please sign in to comment.