From 2de4f11f234c7a33be0ce7aadafbd59f9c849622 Mon Sep 17 00:00:00 2001 From: Pedro Bini Date: Tue, 7 Jul 2020 12:17:49 -0300 Subject: [PATCH] Fix defaultValue overriding falsy values --- packages/core/src/components/FormInput/FormInput.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/src/components/FormInput/FormInput.tsx b/packages/core/src/components/FormInput/FormInput.tsx index c6a7bc4..969a8a2 100644 --- a/packages/core/src/components/FormInput/FormInput.tsx +++ b/packages/core/src/components/FormInput/FormInput.tsx @@ -129,14 +129,16 @@ const FormInput = ({ error: formInputError.hasErrors, }; + const inputValue = value ?? defaultValue ?? formInputMeta.initialValue; + const isUntouched = ( - (value || defaultValue || formInputMeta.initialValue) + !!inputValue && !formInputMeta.touched && !isInitializedRef.current ); if (isUntouched) { - form.setFieldValue(name, value || defaultValue || formInputMeta.initialValue); + form.setFieldValue(name, inputValue); inputProps.defaultValue = undefined; isInitializedRef.current = true;