fix(striker-ui): correct validity test on first render in InputWithRef

main
Tsu-ba-me 2 years ago
parent 10126a5a95
commit 8abd47eb18
  1. 17
      striker-ui/components/InputWithRef.tsx
  2. 4
      striker-ui/components/StrikerConfig/AddPeerDialog.tsx

@ -5,7 +5,6 @@ import {
forwardRef,
ReactElement,
useCallback,
useEffect,
useImperativeHandle,
useMemo,
useState,
@ -26,7 +25,7 @@ type InputWithRefOptionalPropsWithoutDefault<
TypeName extends keyof MapToInputType,
> = {
inputTestBatch?: InputTestBatch;
onFirstRender?: (args: { isRequired: boolean }) => void;
onFirstRender?: InputFirstRenderFunction;
valueKey?: CreateInputOnChangeHandlerOptions<TypeName>['valueKey'];
};
@ -167,11 +166,15 @@ const InputWithRef = forwardRef(
[initOnFocus, inputTestBatch],
);
useEffect(() => {
if (isFirstRender) {
onFirstRender?.call(null, { isRequired });
}
}, [isFirstRender, isRequired, onFirstRender]);
if (isFirstRender) {
const isValid =
testInput?.call(null, {
inputs: { [INPUT_TEST_ID]: { value: inputValue } },
isIgnoreOnCallbacks: true,
}) ?? false;
onFirstRender?.call(null, { isValid });
}
useImperativeHandle(
ref,

@ -61,8 +61,8 @@ const AddPeerDialog = forwardRef<
const buildInputFirstRenderFunction = useCallback(
(key: string) =>
({ isRequired }: { isRequired: boolean }) => {
setFormValidity(buildObjectStateSetterCallback(key, !isRequired));
({ isValid }: InputFirstRenderFunctionArgs) => {
setFormValidity(buildObjectStateSetterCallback(key, isValid));
},
[],
);

Loading…
Cancel
Save