Skip to content

Commit

Permalink
Improved error logic check on Input component
Browse files Browse the repository at this point in the history
  • Loading branch information
ArmandoGraterol committed Jul 1, 2021
1 parent 0fa3982 commit 76704dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/modules/core/components/Fields/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ const Input = ({
<div className={styles.extension}>{extensionStringText}</div>
)}
</div>
{!elementOnly && (((error || forcedFieldError) && touched) || status) && (
{!elementOnly && (
<InputStatus
appearance={appearance}
status={status}
statusValues={statusValues}
error={error || forcedFieldError}
touched={touched}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MessageDescriptor, useIntl } from 'react-intl';
import React from 'react';

import { isNil } from 'lodash';
import { SimpleMessageValues } from '~types/index';
import { getMainClasses } from '~utils/css';

Expand All @@ -26,6 +27,7 @@ interface Props {

/** Values for status text (react-intl interpolation) (if applicable) */
statusValues?: SimpleMessageValues;
touched?: boolean;
}

const displayName = 'InputStatus';
Expand All @@ -35,18 +37,20 @@ const InputStatus = ({
error,
status,
statusValues,
touched,
}: Props) => {
const { formatMessage } = useIntl();
const errorText = typeof error === 'object' ? formatMessage(error) : error;
const statusText =
typeof status === 'object' ? formatMessage(status, statusValues) : status;
const showErrorText = !isNil(touched) && touched;
const text = errorText || statusText;
const Element = appearance.direction === 'horizontal' ? 'span' : 'p';
return (
<Element
className={getMainClasses(appearance, styles, {
error: !!error,
hidden: !text,
hidden: !text || (!!error && !showErrorText),
})}
>
{text}
Expand Down

0 comments on commit 76704dd

Please sign in to comment.