fix: FormItem with help (#23945)

* fix: Help status error

* update logic

* adjust ref

* fix ts

* adjust hidden logic
This commit is contained in:
二货机器人 2020-05-07 23:26:07 +08:00 committed by GitHub
parent 5f825d8172
commit c4b602e835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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',
};