]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16414 Fix Keyboard navigation in Coding rules
authorGuillaume Peoc'h <guillaume.peoch@sonarsource.com>
Mon, 16 May 2022 08:02:15 +0000 (10:02 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 20 May 2022 20:02:46 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx
server/sonar-web/src/main/js/helpers/keycodes.ts

index 5e052bab42cb57679d62decd99f53c359035886a..210d99ccf96443cbea2f5f61af2aef80c75bca8f 100644 (file)
@@ -32,6 +32,7 @@ import SearchBox from '../../../components/controls/SearchBox';
 import Suggestions from '../../../components/embed-docs-modal/Suggestions';
 import BackIcon from '../../../components/icons/BackIcon';
 import '../../../components/search-navigator.css';
+import { KeyboardKeys } from '../../../helpers/keycodes';
 import { translate } from '../../../helpers/l10n';
 import {
   addSideBarClass,
@@ -151,22 +152,28 @@ export class App extends React.PureComponent<Props, State> {
   };
 
   handleKeyPress = (event: KeyboardEvent) => {
-    switch (event.code) {
-      case 'ArrowLeft':
+    const { tagName } = event.target as HTMLElement;
+    const isInput = tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA';
+    if (isInput) {
+      return false;
+    }
+    switch (event.key) {
+      case KeyboardKeys.LeftArrow:
         event.preventDefault();
         this.handleBack();
-        return;
-      case 'ArrowRight':
+        break;
+      case KeyboardKeys.RightArrow:
         event.preventDefault();
         this.openSelectedRule();
-        return;
-      case 'ArrowDown':
+        break;
+      case KeyboardKeys.DownArrow:
         event.preventDefault();
         this.selectNextRule();
-        return;
-      case 'ArrowUp':
+        break;
+      case KeyboardKeys.UpArrow:
         event.preventDefault();
         this.selectPreviousRule();
+        break;
     }
   };
 
index 04c3b908fac896e180f197500aa756a1ede35ffe..c222a202457514cdc8d86fe846a59e811f598e2d 100644 (file)
@@ -40,6 +40,8 @@ export enum KeyboardKeys {
   Escape = 'Escape',
   UpArrow = 'ArrowUp',
   DownArrow = 'ArrowDown',
+  RightArrow = 'ArrowRight',
+  LeftArrow = 'ArrowLeft',
   Enter = 'Enter',
   Space = ' ',
   Alt = 'Alt',