From 6f5e822533c68f2301080f84a91267f8680701d3 Mon Sep 17 00:00:00 2001 From: Allan Oliveira Date: Wed, 24 Apr 2024 09:52:00 -0300 Subject: [PATCH] feat: up auto focus --- package.json | 2 +- src/hooks/useRegisterFieldFocus.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2b26dbc..ffe1c96 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "react", "typescript" ], - "version": "2.3.10", + "version": "2.3.11", "main": "./dist/index.cjs.js", "module": "./dist/index.esm.js", "types": "./dist/index.d.ts", diff --git a/src/hooks/useRegisterFieldFocus.ts b/src/hooks/useRegisterFieldFocus.ts index ce8e444..ab7db45 100644 --- a/src/hooks/useRegisterFieldFocus.ts +++ b/src/hooks/useRegisterFieldFocus.ts @@ -22,10 +22,6 @@ export const useRegisterFieldFocus = (fieldName?: string | undefined) => { const autoFocusContextValue = AutoFocusContext.useContext() - if (fieldName && autoFocusContextValue?.setFocus) { - sequentialFieldNamesRef.current.push(fieldName) - } - const onKeyDown = useCallback( (e: any) => { console.log('autoFocusContextValue', autoFocusContextValue) @@ -69,6 +65,10 @@ export const useRegisterFieldFocus = (fieldName?: string | undefined) => { ) useEffect(() => { + if (fieldName && autoFocusContextValue?.setFocus) { + sequentialFieldNamesRef.current.push(fieldName) + } + return () => { if (!autoFocusContextValue?.setFocus) { return @@ -80,7 +80,9 @@ export const useRegisterFieldFocus = (fieldName?: string | undefined) => { ) } } - }, [autoFocusContextValue?.setFocus, fieldName, sequentialFieldNamesRef]) + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [autoFocusContextValue?.setFocus]) return onKeyDown }