Skip to content

Commit 77344d4

Browse files
committed
Self-review of InputFormField and PasswordFormField
1 parent ea5fec8 commit 77344d4

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/molecules/form-fields/input-form-field.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ const InputFormField: React.RefForwardingComponent<
6464
value,
6565
} = props;
6666

67+
const cssIsValid = isValid ? "" : "-invalid";
6768
const fieldId = props.fieldId ?? uuid.v4();
6869

6970
return (
70-
<div className={`${COMPONENT_CLASS} ${isValid ? "" : "-invalid"}`}>
71+
<div className={`${COMPONENT_CLASS} ${cssIsValid}`}>
7172
<label htmlFor={fieldId}>
7273
{showLabelForScreenReadersOnly ? (
7374
<span className="sr-only">{label}</span>

src/molecules/form-fields/password-form-field.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import uuid from "uuid";
33
import { InputProperties } from "../../atoms/interfaces/input-properties";
44
import { PasswordInput } from "../../atoms/forms/password-input";
55

6+
// -----------------------------------------------------------------------------------------
7+
// #region Constants
8+
// -----------------------------------------------------------------------------------------
9+
10+
const COMPONENT_CLASS = "c-form-field";
11+
12+
// #endregion Constants
13+
614
// -----------------------------------------------------------------------------------------
715
// #region Interfaces
816
// -----------------------------------------------------------------------------------------
@@ -40,9 +48,10 @@ const PasswordFormField: React.FC<PasswordFormFields> = (
4048
value,
4149
} = props;
4250

43-
const fieldId = uuid.v4();
4451
const [isVisible, setIsVisible] = useState<boolean>(false);
52+
const cssIsValid = isValid ? "" : "-invalid";
4553
const disableShowHide = value == null || value === "" || disabled;
54+
const fieldId = uuid.v4();
4655
const passwordShowHideLabel = isVisible ? "Hide" : "Show";
4756

4857
const onChangeIsVisible = (
@@ -58,11 +67,13 @@ const PasswordFormField: React.FC<PasswordFormFields> = (
5867
}
5968

6069
return (
61-
<div className={`c-form-field -password ${isValid ? "" : "-invalid"}`}>
70+
<div className={`${COMPONENT_CLASS} -password ${cssIsValid}`}>
6271
<label htmlFor={fieldId}>
6372
{label}
6473
{required && (
65-
<span className="c-form-field__required">{" *"}</span>
74+
<span className={`${COMPONENT_CLASS}__required`}>
75+
{" *"}
76+
</span>
6677
)}
6778
</label>
6879
{// if
@@ -84,8 +95,8 @@ const PasswordFormField: React.FC<PasswordFormFields> = (
8495
testId={inputTestId}
8596
value={value}
8697
/>
87-
<div className="c-form-field__bottom">
88-
<div className="c-form-field__bottom__errors">
98+
<div className={`${COMPONENT_CLASS}__bottom`}>
99+
<div className={`${COMPONENT_CLASS}__bottom__errors`}>
89100
<label>{errorMessage}</label>
90101
</div>
91102
</div>

0 commit comments

Comments
 (0)