Skip to content

Commit

Permalink
feat: up auto focus
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOliveiraM committed Apr 24, 2024
1 parent 34e3d49 commit 6f5e822
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 7 additions & 5 deletions src/hooks/useRegisterFieldFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -69,6 +65,10 @@ export const useRegisterFieldFocus = (fieldName?: string | undefined) => {
)

useEffect(() => {
if (fieldName && autoFocusContextValue?.setFocus) {
sequentialFieldNamesRef.current.push(fieldName)
}

return () => {
if (!autoFocusContextValue?.setFocus) {
return
Expand All @@ -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
}

0 comments on commit 6f5e822

Please sign in to comment.