fix(striker-ui): add event handler append props in InputWithRef

main
Tsu-ba-me 2 years ago
parent c4704aa298
commit 9878d03ee5
  1. 19
      striker-ui/components/InputWithRef.tsx

@ -25,7 +25,9 @@ type InputWithRefOptionalPropsWithoutDefault<
TypeName extends keyof MapToInputType, TypeName extends keyof MapToInputType,
> = { > = {
inputTestBatch?: InputTestBatch; inputTestBatch?: InputTestBatch;
onBlurAppend?: InputBaseProps['onBlur'];
onFirstRender?: InputFirstRenderFunction; onFirstRender?: InputFirstRenderFunction;
onFocusAppend?: InputBaseProps['onFocus'];
onUnmount?: () => void; onUnmount?: () => void;
valueKey?: CreateInputOnChangeHandlerOptions<TypeName>['valueKey']; valueKey?: CreateInputOnChangeHandlerOptions<TypeName>['valueKey'];
}; };
@ -69,7 +71,9 @@ const InputWithRef = forwardRef(
{ {
input, input,
inputTestBatch, inputTestBatch,
onBlurAppend,
onFirstRender, onFirstRender,
onFocusAppend,
onUnmount, onUnmount,
required: isRequired = INPUT_WITH_REF_DEFAULT_PROPS.required, required: isRequired = INPUT_WITH_REF_DEFAULT_PROPS.required,
valueKey, valueKey,
@ -125,14 +129,20 @@ const InputWithRef = forwardRef(
() => () =>
initOnBlur ?? initOnBlur ??
(testInput && (testInput &&
(({ target: { value } }) => { ((...args) => {
const {
0: {
target: { value },
},
} = args;
const isValid = testInput({ const isValid = testInput({
inputs: { [INPUT_TEST_ID]: { value } }, inputs: { [INPUT_TEST_ID]: { value } },
}); });
setIsInputValid(isValid); setIsInputValid(isValid);
onBlurAppend?.call(null, ...args);
})), })),
[initOnBlur, testInput], [initOnBlur, onBlurAppend, testInput],
); );
const onChange = useMemo( const onChange = useMemo(
() => () =>
@ -160,10 +170,11 @@ const InputWithRef = forwardRef(
() => () =>
initOnFocus ?? initOnFocus ??
(inputTestBatch && (inputTestBatch &&
(() => { ((...args) => {
inputTestBatch.defaults?.onSuccess?.call(null, { append: {} }); inputTestBatch.defaults?.onSuccess?.call(null, { append: {} });
onFocusAppend?.call(null, ...args);
})), })),
[initOnFocus, inputTestBatch], [initOnFocus, inputTestBatch, onFocusAppend],
); );
/** /**

Loading…
Cancel
Save