Skip to content

Commit

Permalink
fix(form): 🐛 Cannot read properties of undefined (reading 'autoFocus' (
Browse files Browse the repository at this point in the history
…ant-design#4419)

Co-authored-by: dengqing <qing.deng@goldenpig.com.cn>
  • Loading branch information
Dunqing and dengqing committed Jan 7, 2022
1 parent efa9023 commit 0aea58d
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions packages/field/src/components/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,30 @@ const FieldText: ProFieldFC<{
text: string;
emptyText?: React.ReactNode;
}> = ({ text, mode, render, renderFormItem, fieldProps, emptyText = '-' }, ref) => {
const { autoFocus, prefix = '', suffix = '' } = fieldProps || {};

const intl = useIntl();
const inputRef = useRef<HTMLInputElement>();
useImperativeHandle(ref, () => inputRef.current);
useEffect(() => {
if (fieldProps.autoFocus) {
inputRef?.current?.focus();
if (autoFocus) {
inputRef.current?.focus();
}
}, [fieldProps.autoFocus]);
}, [autoFocus]);

if (mode === 'read') {
const dom = text ?? emptyText;

if (render) {
return (
render(
text,
{ mode, ...fieldProps },
<>
{fieldProps?.prefix || ''}
{dom}
{fieldProps?.suffix || ''}
</>,
) ?? emptyText
);
}
return (
const dom = (
<>
{fieldProps?.prefix || ''}
{dom}
{fieldProps?.suffix || ''}
{prefix}
{text ?? emptyText}
{suffix}
</>
);

if (render) {
return render(text, { mode, ...fieldProps }, dom) ?? emptyText;
}
return dom;
}
if (mode === 'edit' || mode === 'update') {
const placeholder = intl.getMessage('tableForm.inputPlaceholder', '请输入');
Expand Down

0 comments on commit 0aea58d

Please sign in to comment.