From 99abea607cabc437b824fdd5813d0c5bfd7ee1b6 Mon Sep 17 00:00:00 2001 From: JiaxiangZhang Date: Sun, 26 Apr 2026 16:59:57 +0800 Subject: [PATCH 1/3] refactor(Digit): remove unused utility functions and simplify FieldDigitEdit component - Deleted the isEmptyOrWhitespace utility function as it was no longer needed. - Simplified the FieldDigitEdit component by removing the proxyChange logic and directly passing fieldProps to InputNumber. - Cleaned up imports in the index file to reflect the changes. --- src/field/components/Digit/FieldDigitEdit.tsx | 26 +++------------- src/field/components/Digit/digitUtils.ts | 5 --- src/field/components/Digit/index.tsx | 31 +------------------ tests/form/base.test.tsx | 12 +++++-- 4 files changed, 15 insertions(+), 59 deletions(-) delete mode 100644 src/field/components/Digit/digitUtils.ts diff --git a/src/field/components/Digit/FieldDigitEdit.tsx b/src/field/components/Digit/FieldDigitEdit.tsx index 706c1d1bb98e..a220e4cbddb4 100644 --- a/src/field/components/Digit/FieldDigitEdit.tsx +++ b/src/field/components/Digit/FieldDigitEdit.tsx @@ -1,13 +1,10 @@ -import { omit } from '@rc-component/util'; -import { InputNumber } from 'antd'; +import { InputNumber } from 'antd'; import React from 'react'; import type { ProFieldFC } from '../../types'; -import { isEmptyOrWhitespace } from './digitUtils'; import type { FieldDigitProps } from './types'; type Props = Parameters>[0] & { placeholderValue: string; - proxyChange: (value: number | string | null) => number | string | undefined; }; export function FieldDigitEdit(props: Props, ref: React.Ref) { @@ -17,28 +14,13 @@ export function FieldDigitEdit(props: Props, ref: React.Ref) { formItemRender, fieldProps, placeholderValue, - proxyChange, } = props; const dom = ( - - ref={ref as React.Ref} + fieldProps?.onChange?.(proxyChange(e))} - onBlur={(e) => { - const value = e.target.value; - if (isEmptyOrWhitespace(value)) { - fieldProps?.onBlur?.(e); - return; - } - const processedValue = proxyChange(value); - if (e.target && typeof processedValue === 'number') { - e.target.value = processedValue.toString(); - fieldProps?.onChange?.(processedValue); - } - fieldProps?.onBlur?.(e); - }} + {...fieldProps} /> ); if (formItemRender) { diff --git a/src/field/components/Digit/digitUtils.ts b/src/field/components/Digit/digitUtils.ts deleted file mode 100644 index 4ffb9d8532c8..000000000000 --- a/src/field/components/Digit/digitUtils.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { isNil } from '../../../utils'; - -export function isEmptyOrWhitespace(str?: string): boolean { - return isNil(str) || str === '' || str?.trim() === ''; -} diff --git a/src/field/components/Digit/index.tsx b/src/field/components/Digit/index.tsx index 66f3b100576b..67122e85a0c5 100644 --- a/src/field/components/Digit/index.tsx +++ b/src/field/components/Digit/index.tsx @@ -1,6 +1,5 @@ -import React, { useCallback } from 'react'; +import React from 'react'; import { useIntl } from '../../../provider'; -import { isNil } from '../../../utils'; import { isProFieldEditOrUpdateMode, isProFieldReadMode, @@ -22,34 +21,7 @@ const FieldDigit: ProFieldFC = ( const intl = useIntl(); const placeholderValue = placeholder || intl.getMessage('tableForm.inputPlaceholder', '请输入'); - const proxyChange = useCallback( - (value: number | string | null) => { - let val = value ?? undefined; - if (!fieldProps.stringMode && typeof val === 'string') { - const numVal = Number(val); - if (isNaN(numVal)) { - const match = val.match(/^(\d+(?:\.\d+)?)/); - if (match) { - val = Number(match[1]); - } else { - val = undefined; - } - } else { - val = numVal; - } - } - if ( - typeof val === 'number' && - !isNil(val) && - !isNil(fieldProps.precision) - ) { - val = Number(val.toFixed(fieldProps.precision)); - } - return val; - }, - [fieldProps], - ); if (isProFieldReadMode(type)) { return FieldDigitRead( { text, mode: type, render, placeholder, formItemRender, fieldProps }, @@ -66,7 +38,6 @@ const FieldDigit: ProFieldFC = ( formItemRender, fieldProps, placeholderValue, - proxyChange, }, ref, ); diff --git a/tests/form/base.test.tsx b/tests/form/base.test.tsx index 8c5941e90b44..9fb37f67de58 100644 --- a/tests/form/base.test.tsx +++ b/tests/form/base.test.tsx @@ -3575,10 +3575,18 @@ describe('ProForm', () => { await act(async () => { fireEvent.change(dom, { target: { - value: '22.22.22', + value: '22.22', // 先建立合法的 decimalValue = 22.22 }, }); - fireEvent.blur(dom); + }); + + await act(async () => { + fireEvent.change(dom, { + target: { + value: '22.22.22', // 再设置非法字符串 + }, + }); + fireEvent.blur(dom); // blur 回退到 decimalValue → precision=0 → 22 }); await act(async () => { From de6530e45dcb4f681a8e3fad9b5e6e878d7444fd Mon Sep 17 00:00:00 2001 From: JiaxiangZhang Date: Sun, 26 Apr 2026 17:45:58 +0800 Subject: [PATCH 2/3] feat(layout): add ProFormDigit component for percentage input and adjust submission wait time - Introduced ProFormDigit for capturing percentage values with precision and an addon for '%' symbol. - Reduced the wait time for form submission feedback from 2000ms to 500ms for improved user experience. --- demos/form/layout-change.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/demos/form/layout-change.tsx b/demos/form/layout-change.tsx index 055fb6e232ce..1566e0ce987b 100644 --- a/demos/form/layout-change.tsx +++ b/demos/form/layout-change.tsx @@ -13,6 +13,7 @@ import { ModalForm, ProForm, ProFormDateRangePicker, + ProFormDigit, ProFormRadio, ProFormSelect, ProFormText, @@ -263,8 +264,7 @@ const Demo = () => { } onFinish={async (values: any) => { - await waitTime(2000); - + await waitTime(500); message.success('Submission successful'); }} initialValues={{ @@ -340,6 +340,17 @@ const Demo = () => { label="Business Manager" initialValue="书琰" /> + From b10ea7e5671430f313f781cc61909a67d13c16b0 Mon Sep 17 00:00:00 2001 From: JiaxiangZhang Date: Sun, 26 Apr 2026 18:10:05 +0800 Subject: [PATCH 3/3] fix(layout): update label for ProFormDigit component from "percent" to "Percent" for consistency --- demos/form/layout-change.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/form/layout-change.tsx b/demos/form/layout-change.tsx index 1566e0ce987b..828e92c23c8e 100644 --- a/demos/form/layout-change.tsx +++ b/demos/form/layout-change.tsx @@ -342,7 +342,7 @@ const Demo = () => { />