diff --git a/components/config-provider/__tests__/__snapshots__/components.test.tsx.snap b/components/config-provider/__tests__/__snapshots__/components.test.tsx.snap index 5a57c1c193..98cea82afd 100644 --- a/components/config-provider/__tests__/__snapshots__/components.test.tsx.snap +++ b/components/config-provider/__tests__/__snapshots__/components.test.tsx.snap @@ -15699,7 +15699,8 @@ exports[`ConfigProvider components Form configProvider 1`] = `
-
@@ -15754,7 +15752,8 @@ exports[`ConfigProvider components Form configProvider componentDisabled 1`] = `
-
@@ -15808,7 +15804,8 @@ exports[`ConfigProvider components Form configProvider componentSize large 1`] =
-
@@ -15862,7 +15856,8 @@ exports[`ConfigProvider components Form configProvider componentSize middle 1`]
-
@@ -15916,7 +15908,8 @@ exports[`ConfigProvider components Form configProvider componentSize small 1`] =
-
@@ -15970,7 +15960,8 @@ exports[`ConfigProvider components Form normal 1`] = `
-
@@ -16024,7 +16012,8 @@ exports[`ConfigProvider components Form prefixCls 1`] = `
-
diff --git a/components/form/FormItemInput.tsx b/components/form/FormItemInput.tsx index 741a86d920..6719391a70 100644 --- a/components/form/FormItemInput.tsx +++ b/components/form/FormItemInput.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import classNames from 'classnames'; +import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; import type { ColProps } from '../grid/col'; import Col from '../grid/col'; @@ -65,6 +66,16 @@ const FormItemInput: React.FC = (pr delete subFormContext.labelCol; delete subFormContext.wrapperCol; + const extraRef = React.useRef(null); + const [extraHeight, setExtraHeight] = React.useState(0); + useLayoutEffect(() => { + if (extra && extraRef.current) { + setExtraHeight(extraRef.current.clientHeight); + } else { + setExtraHeight(0); + } + }, [extra]); + const inputDom: React.ReactNode = (
{children}
@@ -73,20 +84,17 @@ const FormItemInput: React.FC = (pr const formItemContext = React.useMemo(() => ({ prefixCls, status }), [prefixCls, status]); const errorListDom: React.ReactNode = marginBottom !== null || errors.length || warnings.length ? ( -
- - - - {!!marginBottom &&
} -
+ + + ) : null; const extraProps: { id?: string } = {}; @@ -98,19 +106,29 @@ const FormItemInput: React.FC = (pr // If extra = 0, && will goes wrong // 0&&error -> 0 const extraDom: React.ReactNode = extra ? ( -
+
{extra}
) : null; + const additionalDom: React.ReactNode = + errorListDom || extraDom ? ( +
+ {errorListDom} + {extraDom} +
+ ) : null; + const dom: React.ReactNode = formItemRender && formItemRender.mark === 'pro_table_render' && formItemRender.render ? ( formItemRender.render(props, { input: inputDom, errorList: errorListDom, extra: extraDom }) ) : ( <> {inputDom} - {errorListDom} - {extraDom} + {additionalDom} ); return ( diff --git a/components/form/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/form/__tests__/__snapshots__/demo-extend.test.ts.snap index 7c360ad316..742beb3a97 100644 --- a/components/form/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/form/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -2010,7 +2010,8 @@ exports[`renders components/form/demo/custom-feedback-icons.tsx extend context c
-
@@ -2076,7 +2074,8 @@ exports[`renders components/form/demo/custom-feedback-icons.tsx extend context c
-
@@ -6102,7 +6098,8 @@ exports[`renders components/form/demo/disabled-input-debug.tsx extend context co
-
@@ -6161,7 +6155,8 @@ exports[`renders components/form/demo/disabled-input-debug.tsx extend context co
-
@@ -6255,7 +6247,8 @@ exports[`renders components/form/demo/disabled-input-debug.tsx extend context co
-
@@ -6314,7 +6304,8 @@ exports[`renders components/form/demo/disabled-input-debug.tsx extend context co
-
@@ -6434,7 +6422,8 @@ exports[`renders components/form/demo/disabled-input-debug.tsx extend context co
-
@@ -6506,7 +6492,8 @@ exports[`renders components/form/demo/disabled-input-debug.tsx extend context co
-
@@ -6618,7 +6602,8 @@ exports[`renders components/form/demo/disabled-input-debug.tsx extend context co
-
@@ -6686,7 +6668,8 @@ exports[`renders components/form/demo/disabled-input-debug.tsx extend context co
-
@@ -11247,9 +11227,13 @@ exports[`renders components/form/demo/register.tsx extend context correctly 1`]
- We must make sure that your are a human. +
+ We must make sure that your are a human. +
@@ -22983,10 +22967,14 @@ exports[`renders components/form/demo/validate-other.tsx extend context correctl
- longgggggggggggggggggggggggggggggggggg +
+ longgggggggggggggggggggggggggggggggggg +
@@ -23965,7 +23953,8 @@ exports[`renders components/form/demo/validate-static.tsx extend context correct
-
@@ -24119,7 +24105,8 @@ exports[`renders components/form/demo/validate-static.tsx extend context correct
-
@@ -24346,7 +24330,8 @@ exports[`renders components/form/demo/validate-static.tsx extend context correct
-
@@ -28257,7 +28239,8 @@ exports[`renders components/form/demo/validate-static.tsx extend context correct
-
@@ -28470,7 +28450,8 @@ exports[`renders components/form/demo/validate-static.tsx extend context correct
-
@@ -29152,7 +29130,8 @@ exports[`renders components/form/demo/validate-static.tsx extend context correct
-
@@ -30634,7 +30610,8 @@ exports[`renders components/form/demo/validate-static.tsx extend context correct
-
@@ -33736,7 +33710,8 @@ exports[`renders components/form/demo/without-form-create.tsx extend context cor
-
diff --git a/components/form/__tests__/__snapshots__/demo.test.tsx.snap b/components/form/__tests__/__snapshots__/demo.test.tsx.snap index 6f0a8ba9c2..1e41054957 100644 --- a/components/form/__tests__/__snapshots__/demo.test.tsx.snap +++ b/components/form/__tests__/__snapshots__/demo.test.tsx.snap @@ -7183,9 +7183,13 @@ exports[`renders components/form/demo/register.tsx correctly 1`] = `
- We must make sure that your are a human. +
+ We must make sure that your are a human. +
@@ -10383,10 +10387,14 @@ exports[`renders components/form/demo/validate-other.tsx correctly 1`] = `
- longgggggggggggggggggggggggggggggggggg +
+ longgggggggggggggggggggggggggggggggggg +
diff --git a/components/form/style/explain.ts b/components/form/style/explain.ts index 5ecff1d489..695fe83609 100644 --- a/components/form/style/explain.ts +++ b/components/form/style/explain.ts @@ -10,7 +10,7 @@ const genFormValidateMotionStyle: GenerateStyle = (token) => { return { [helpCls]: { // Explain holder - transition: `opacity ${token.motionDurationSlow} ${token.motionEaseInOut}`, + transition: `opacity ${token.motionDurationFast} ${token.motionEaseInOut}`, '&-appear, &-enter': { opacity: 0, @@ -31,9 +31,9 @@ const genFormValidateMotionStyle: GenerateStyle = (token) => { // Explain [helpItemCls]: { overflow: 'hidden', - transition: `height ${token.motionDurationSlow} ${token.motionEaseInOut}, - opacity ${token.motionDurationSlow} ${token.motionEaseInOut}, - transform ${token.motionDurationSlow} ${token.motionEaseInOut} !important`, + transition: `height ${token.motionDurationFast} ${token.motionEaseInOut}, + opacity ${token.motionDurationFast} ${token.motionEaseInOut}, + transform ${token.motionDurationFast} ${token.motionEaseInOut} !important`, [`&${helpItemCls}-appear, &${helpItemCls}-enter`]: { transform: `translateY(-5px)`, diff --git a/components/form/style/index.ts b/components/form/style/index.ts index e36fadcc2d..970629bb09 100644 --- a/components/form/style/index.ts +++ b/components/form/style/index.ts @@ -8,8 +8,8 @@ import type { AliasToken, FullToken, GenerateStyle, - GetDefaultToken, GenStyleFn, + GetDefaultToken, } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; import genFormValidateMotionStyle from './explain'; @@ -339,6 +339,11 @@ const genFormItemStyle: GenerateStyle = (token) => { // = Explain = // ============================================================== [formItemCls]: { + '&-additional': { + display: 'flex', + flexDirection: 'column', + }, + '&-explain, &-extra': { clear: 'both', color: token.colorTextDescription,