From 6ec94d7182bdd9437ae8485babbe40179b838fdd Mon Sep 17 00:00:00 2001 From: mikolajmeller Date: Wed, 2 Dec 2020 09:56:20 +0100 Subject: [PATCH] Properly handle arrow up key in search suggestion navigation --- .../components/Search/Search.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/source/components/GlobalNavigation/components/Search/Search.js b/source/components/GlobalNavigation/components/Search/Search.js index b2d1ae81..b458cf30 100644 --- a/source/components/GlobalNavigation/components/Search/Search.js +++ b/source/components/GlobalNavigation/components/Search/Search.js @@ -78,28 +78,27 @@ class Search extends React.Component { event.stopPropagation(); - switch (event.keyCode) { - // down arrow - case 40: + switch (event.key) { + case "Down": + case "ArrowDown": if (selectedSuggestionIndex < suggestions.length - 1) { this.setState({ selectedSuggestionIndex: selectedSuggestionIndex + 1 }); } break; - // up arrow - case 30: + case "Up": + case "ArrowUp": if (suggestions.length && selectedSuggestionIndex > -1) { this.setState(({ selectedSuggestionIndex: selectedSuggestionIndex - 1 })); } break; - // ESC key - case 27: + case "Esc": + case "Escape": this.onSearchClose(); break; - // ENTER key - case 13: + case "Enter": if (selectedSuggestionIndex !== -1) { onSearchSuggestionChosen(suggestions[selectedSuggestionIndex], suggestions, suggestionId); this.input.current.blur();