]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16946 Function cannot be performed by keyboard alone
authorMathieu Suen <mathieu.suen@sonarsource.com>
Fri, 7 Oct 2022 08:32:01 +0000 (10:32 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 7 Oct 2022 20:03:00 +0000 (20:03 +0000)
server/sonar-web/src/main/js/components/common/MultiSelect.tsx
server/sonar-web/src/main/js/components/hoc/withKeyboardNavigation.tsx

index 703df7b833ff35dd758bf9c797506e08bdfeb3cd..ff01303af8009018096d53859970f2efab58e5cb 100644 (file)
@@ -118,7 +118,7 @@ export default class MultiSelect extends React.PureComponent<PropsWithDefault, S
   componentWillUnmount() {
     this.mounted = false;
     if (this.container) {
-      this.container.removeEventListener('keydown', this.handleKeyboard);
+      this.container.removeEventListener('keydown', this.handleKeyboard, true);
     }
   }
 
index e69e696c266725437db8a9b281429553c108cb59..ecfacd0054fd697193960d4cbfdb17578a375192 100644 (file)
@@ -55,20 +55,16 @@ export default function withKeyboardNavigation<P>(
         return true;
       }
       if (event.key === KeyboardKeys.UpArrow) {
-        event.preventDefault();
-        return this.skipIfFile(this.handleHighlightPrevious);
+        return this.skipIfFile(event, this.handleHighlightPrevious);
       } else if (event.key === KeyboardKeys.DownArrow) {
-        event.preventDefault();
-        return this.skipIfFile(this.handleHighlightNext);
+        return this.skipIfFile(event, this.handleHighlightNext);
       } else if (event.key === KeyboardKeys.RightArrow || event.key === KeyboardKeys.Enter) {
-        event.preventDefault();
-        return this.skipIfFile(this.handleSelectCurrent);
+        return this.skipIfFile(event, this.handleSelectCurrent);
       } else if (event.key === KeyboardKeys.LeftArrow) {
-        event.preventDefault();
         this.handleSelectParent();
         return false; // always hijack left / Why did you put this @wouter?
       }
-      return false;
+      return true;
     };
 
     getCurrentIndex = () => {
@@ -81,10 +77,11 @@ export default function withKeyboardNavigation<P>(
         : -1;
     };
 
-    skipIfFile = (handler: () => void) => {
+    skipIfFile = (event: KeyboardEvent, handler: () => void) => {
       if (this.props.isFile) {
         return true;
       }
+      event.preventDefault();
       handler();
       return false;
     };