Skip to content

Accessible search bar with arrow keys #793

Discussion options

You must be logged in to vote

From what i can see there are 2 things we need to look at.

  1. We need to do one thing if it is a "normal" search. If not, i.e. the user is scrolling through the history then we want to do another thing.
  2. We need to figure out what search term is the one currently being highlighted (i.e. at the currentIndex). Once we have that search term we can do what we like with it... i.e do a new fuse search or update the value on your inputRef etc.
if (event.key === "Enter" && currentIndex === -1) {
      updateLastSearches(searchTerm);
    }
if (event.key === "Enter" && currentIndex >= 0) {
  const newSearchTerm = lastSearches[currentIndex];
}

Hopefully this helps.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@onemanwenttomow
Comment options

Answer selected by NadjaKanunnikow
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
2 participants