Skip to content

Commit

Permalink
refactor: change keydown handling in SearchInput component to navigat…
Browse files Browse the repository at this point in the history
…e using input ref value
  • Loading branch information
ThomasGross committed Jan 15, 2025
1 parent 1ff8eb8 commit edfa7dc
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions components/shared/searchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ const SearchInput = ({ className, placeholder }: SearchInputProps) => {
// We choose to ignore the eslint warning below
// because we do not want to add the handleKeydown callback which changes on every render.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentQuery])
}, [])

const handleKeydown = () => (event: KeyboardEvent) => {
if (!currentQuery) return
const focusedElement = document.activeElement as HTMLElement

if (event.key === "Enter" && focusedElement === inputRef.current) {
navigateToSearch(currentQuery)
navigateToSearch(inputRef.current.value)
}
}

Expand Down

0 comments on commit edfa7dc

Please sign in to comment.