Skip to content

Commit 03f4568

Browse files
committed
Incubator.TextField - fix initial validity (wix#2096)
(cherry picked from commit 6d7cb2a)
1 parent f42e4fc commit 03f4568

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/incubator/TextField/useFieldState.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function useFieldState({
1515
}: FieldStateProps) {
1616
const [value, setValue] = useState(props.value);
1717
const [isFocused, setIsFocused] = useState(false);
18-
const [isValid, setIsValid] = useState(true);
18+
const [isValid, setIsValid] = useState<boolean | undefined>(undefined);
1919
const [failingValidatorIndex, setFailingValidatorIndex] = useState<number | undefined>(undefined);
2020

2121
useEffect(() => {
@@ -37,7 +37,9 @@ export default function useFieldState({
3737
}, [props.value, validateOnChange]);
3838

3939
useDidUpdate(() => {
40-
onChangeValidity?.(isValid);
40+
if (!_.isUndefined(isValid)) {
41+
onChangeValidity?.(isValid);
42+
}
4143
}, [isValid]);
4244

4345
const checkValidity = useCallback((valueToValidate = value) => {
@@ -86,7 +88,7 @@ export default function useFieldState({
8688
return {
8789
value,
8890
hasValue: !_.isEmpty(value),
89-
isValid: validationMessage && !validate ? false : isValid,
91+
isValid: validationMessage && !validate ? false : isValid ?? true,
9092
isFocused,
9193
failingValidatorIndex
9294
};

0 commit comments

Comments
 (0)