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

main
Tsu-ba-me 2 years ago committed by digimer
parent 0c1ec5a88a
commit afdd376759
  1. 17
      striker-ui/components/InputWithRef.tsx
  2. 4
      striker-ui/components/StrikerConfig/AddPeerDialog.tsx

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

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

Loading…
Cancel
Save