Skip to content

Commit

Permalink
CMS-582: Update onKeyDown event on advisory event typeahead search (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ayumi-oxd authored Dec 17, 2024
1 parent 85fd1b4 commit a5b6081
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/gatsby/src/components/advisories/advisoryFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,33 @@ const AdvisoryFilter = ({
updateAdvisoriesSearchText("")
}
const handleKeyDownInput = (e) => {
if (e.key === 'Enter') {
if (!hasResult(eventText)) {
setIsDropdownOpen(false)
const optionsLength = typeaheadRef.current.items.length
let activeIndex = typeaheadRef.current.state.activeIndex
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
e.preventDefault()
if (e.key === 'ArrowUp') {
activeIndex = activeIndex - 1
} else if (e.key === 'ArrowDown') {
activeIndex = activeIndex + 1
}
if (activeIndex > optionsLength) {
activeIndex = -1 // go to the text input
}
if (activeIndex < -1) {
activeIndex = optionsLength - 1 // go to the last item
}
typeaheadRef.current.setState({ activeIndex })
} else if (e.key === 'Enter') {
e.preventDefault()
const activeOption = typeaheadRef.current.items[activeIndex]
if (activeOption !== undefined) {
handleTypeaheadChange([activeOption])
} else {
handleSearch()
}
setIsDropdownOpen(false)
} else if (e.key === 'Tab') {
setIsDropdownOpen(false)
}
}

Expand Down

0 comments on commit a5b6081

Please sign in to comment.