Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change keydown handling in SearchInput component to navigate using input ref value #89

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading