|
|
|
@ -13,7 +13,6 @@ import { |
|
|
|
|
|
|
|
|
|
import createInputOnChangeHandler from '../lib/createInputOnChangeHandler'; |
|
|
|
|
import { createTestInputFunction } from '../lib/test_input'; |
|
|
|
|
import useIsFirstRender from '../hooks/useIsFirstRender'; |
|
|
|
|
|
|
|
|
|
type InputWithRefOptionalPropsWithDefault< |
|
|
|
|
TypeName extends keyof MapToInputType, |
|
|
|
@ -27,6 +26,7 @@ type InputWithRefOptionalPropsWithoutDefault< |
|
|
|
|
> = { |
|
|
|
|
inputTestBatch?: InputTestBatch; |
|
|
|
|
onFirstRender?: InputFirstRenderFunction; |
|
|
|
|
onUnmount?: () => void; |
|
|
|
|
valueKey?: CreateInputOnChangeHandlerOptions<TypeName>['valueKey']; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -70,6 +70,7 @@ const InputWithRef = forwardRef( |
|
|
|
|
input, |
|
|
|
|
inputTestBatch, |
|
|
|
|
onFirstRender, |
|
|
|
|
onUnmount, |
|
|
|
|
required: isRequired = INPUT_WITH_REF_DEFAULT_PROPS.required, |
|
|
|
|
valueKey, |
|
|
|
|
valueType = INPUT_WITH_REF_DEFAULT_PROPS.valueType as TypeName, |
|
|
|
@ -97,8 +98,6 @@ const InputWithRef = forwardRef( |
|
|
|
|
...restInitProps |
|
|
|
|
} = inputProps; |
|
|
|
|
|
|
|
|
|
const isFirstRender = useIsFirstRender(); |
|
|
|
|
|
|
|
|
|
const [inputValue, setInputValue] = |
|
|
|
|
useState<MapToInputType[TypeName]>(initValue); |
|
|
|
|
const [isChangedByUser, setIsChangedByUser] = useState<boolean>(false); |
|
|
|
@ -175,7 +174,6 @@ const InputWithRef = forwardRef( |
|
|
|
|
* render function completes. |
|
|
|
|
*/ |
|
|
|
|
useEffect(() => { |
|
|
|
|
if (isFirstRender) { |
|
|
|
|
const isValid = |
|
|
|
|
testInput?.call(null, { |
|
|
|
|
inputs: { [INPUT_TEST_ID]: { value: inputValue } }, |
|
|
|
@ -183,8 +181,11 @@ const InputWithRef = forwardRef( |
|
|
|
|
}) ?? false; |
|
|
|
|
|
|
|
|
|
onFirstRender?.call(null, { isValid }); |
|
|
|
|
} |
|
|
|
|
}, [inputValue, isFirstRender, onFirstRender, testInput]); |
|
|
|
|
|
|
|
|
|
return onUnmount; |
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
useImperativeHandle( |
|
|
|
|
ref, |
|
|
|
|