From 9878d03ee5d5a64d306330e7a67df06d51b53253 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Tue, 4 Apr 2023 23:09:20 -0400 Subject: [PATCH] fix(striker-ui): add event handler append props in InputWithRef --- striker-ui/components/InputWithRef.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/striker-ui/components/InputWithRef.tsx b/striker-ui/components/InputWithRef.tsx index 7c0ad269..00faccd7 100644 --- a/striker-ui/components/InputWithRef.tsx +++ b/striker-ui/components/InputWithRef.tsx @@ -25,7 +25,9 @@ type InputWithRefOptionalPropsWithoutDefault< TypeName extends keyof MapToInputType, > = { inputTestBatch?: InputTestBatch; + onBlurAppend?: InputBaseProps['onBlur']; onFirstRender?: InputFirstRenderFunction; + onFocusAppend?: InputBaseProps['onFocus']; onUnmount?: () => void; valueKey?: CreateInputOnChangeHandlerOptions['valueKey']; }; @@ -69,7 +71,9 @@ const InputWithRef = forwardRef( { input, inputTestBatch, + onBlurAppend, onFirstRender, + onFocusAppend, onUnmount, required: isRequired = INPUT_WITH_REF_DEFAULT_PROPS.required, valueKey, @@ -125,14 +129,20 @@ const InputWithRef = forwardRef( () => initOnBlur ?? (testInput && - (({ target: { value } }) => { + ((...args) => { + const { + 0: { + target: { value }, + }, + } = args; const isValid = testInput({ inputs: { [INPUT_TEST_ID]: { value } }, }); setIsInputValid(isValid); + onBlurAppend?.call(null, ...args); })), - [initOnBlur, testInput], + [initOnBlur, onBlurAppend, testInput], ); const onChange = useMemo( () => @@ -160,10 +170,11 @@ const InputWithRef = forwardRef( () => initOnFocus ?? (inputTestBatch && - (() => { + ((...args) => { inputTestBatch.defaults?.onSuccess?.call(null, { append: {} }); + onFocusAppend?.call(null, ...args); })), - [initOnFocus, inputTestBatch], + [initOnFocus, inputTestBatch, onFocusAppend], ); /**