mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
fix: FormItem with help (#23945)
* fix: Help status error * update logic * adjust ref * fix ts * adjust hidden logic
This commit is contained in:
parent
5f825d8172
commit
c4b602e835
@ -82,6 +82,7 @@ function FormItem(props: FormItemProps): React.ReactElement {
|
||||
const formContext = React.useContext(FormContext);
|
||||
const { updateItemErrors } = React.useContext(FormItemContext);
|
||||
const [domErrorVisible, innerSetDomErrorVisible] = React.useState(!!help);
|
||||
const prevValidateStatusRef = React.useRef<ValidateStatus | undefined>(validateStatus);
|
||||
const [inlineErrors, setInlineErrors] = useFrameState<Record<string, string[]>>({});
|
||||
|
||||
function setDomErrorVisible(visible: boolean) {
|
||||
@ -155,6 +156,10 @@ function FormItem(props: FormItemProps): React.ReactElement {
|
||||
mergedValidateStatus = 'success';
|
||||
}
|
||||
|
||||
if (domErrorVisible && help) {
|
||||
prevValidateStatusRef.current = mergedValidateStatus;
|
||||
}
|
||||
|
||||
const itemClassName = {
|
||||
[`${prefixCls}-item`]: true,
|
||||
[`${prefixCls}-item-with-help`]: domErrorVisible || help,
|
||||
@ -166,7 +171,7 @@ function FormItem(props: FormItemProps): React.ReactElement {
|
||||
[`${prefixCls}-item-has-warning`]: mergedValidateStatus === 'warning',
|
||||
[`${prefixCls}-item-has-error`]: mergedValidateStatus === 'error',
|
||||
[`${prefixCls}-item-has-error-leave`]:
|
||||
!help && domErrorVisible && mergedValidateStatus !== 'error',
|
||||
!help && domErrorVisible && prevValidateStatusRef.current === 'error',
|
||||
[`${prefixCls}-item-is-validating`]: mergedValidateStatus === 'validating',
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user