Skip to content

Commit 6ec94d7

Browse files
committed
Properly handle arrow up key in search suggestion navigation
1 parent 8bb74f8 commit 6ec94d7

File tree

1 file changed

+8
-9
lines changed
  • source/components/GlobalNavigation/components/Search

1 file changed

+8
-9
lines changed

source/components/GlobalNavigation/components/Search/Search.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,27 @@ class Search extends React.Component {
7878

7979
event.stopPropagation();
8080

81-
switch (event.keyCode) {
82-
// down arrow
83-
case 40:
81+
switch (event.key) {
82+
case "Down":
83+
case "ArrowDown":
8484
if (selectedSuggestionIndex < suggestions.length - 1) {
8585
this.setState({ selectedSuggestionIndex: selectedSuggestionIndex + 1 });
8686
}
8787

8888
break;
89-
// up arrow
90-
case 30:
89+
case "Up":
90+
case "ArrowUp":
9191
if (suggestions.length && selectedSuggestionIndex > -1) {
9292
this.setState(({ selectedSuggestionIndex: selectedSuggestionIndex - 1 }));
9393
}
9494

9595
break;
96-
// ESC key
97-
case 27:
96+
case "Esc":
97+
case "Escape":
9898
this.onSearchClose();
9999

100100
break;
101-
// ENTER key
102-
case 13:
101+
case "Enter":
103102
if (selectedSuggestionIndex !== -1) {
104103
onSearchSuggestionChosen(suggestions[selectedSuggestionIndex], suggestions, suggestionId);
105104
this.input.current.blur();

0 commit comments

Comments
 (0)