Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/components/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export interface FormItemInstance {
resetValidate?: () => void;
}

const READONLY_SUPPORTED_COMP = ['Input', 'Textarea', 'InputNumber', 'TagInput', 'RadioGroup', 'Select', 'ColorPicker'];

const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref) => {
const [locale, t] = useLocaleReceiver('form');
const { classPrefix, form: globalFormConfig } = useConfig();
Expand Down Expand Up @@ -524,9 +526,13 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
ctrlKey = ctrlKeyMap.get(child.type) || 'value';
}
const childProps = child.props as any;
return React.cloneElement(child, {

// @ts-ignore
const readOnlyKey = READONLY_SUPPORTED_COMP.includes(child?.type?.displayName) ? 'readonly' : 'readOnly';

const cloneProps = {
disabled: disabledFromContext,
readOnly: readonlyFromContext,
[readOnlyKey]: readonlyFromContext,
...childProps,
[ctrlKey]: formValue,
onChange: (value: any, ...args: any[]) => {
Expand All @@ -538,7 +544,8 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
handleItemBlur();
childProps?.onBlur?.call?.(null, value, ...args);
},
});
};
return React.cloneElement(child, cloneProps);
}
return child;
})}
Expand Down
Loading