From b3ad2f5a5b28a9756efd2f2dfe926cd8b2704332 Mon Sep 17 00:00:00 2001 From: Guillaume Peoc'h Date: Mon, 16 May 2022 10:02:15 +0200 Subject: [PATCH] SONAR-16414 Fix Keyboard navigation in Coding rules --- .../js/apps/coding-rules/components/App.tsx | 23 ++++++++++++------- .../sonar-web/src/main/js/helpers/keycodes.ts | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx index 5e052bab42c..210d99ccf96 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx @@ -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 { }; 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; } }; diff --git a/server/sonar-web/src/main/js/helpers/keycodes.ts b/server/sonar-web/src/main/js/helpers/keycodes.ts index 04c3b908fac..c222a202457 100644 --- a/server/sonar-web/src/main/js/helpers/keycodes.ts +++ b/server/sonar-web/src/main/js/helpers/keycodes.ts @@ -40,6 +40,8 @@ export enum KeyboardKeys { Escape = 'Escape', UpArrow = 'ArrowUp', DownArrow = 'ArrowDown', + RightArrow = 'ArrowRight', + LeftArrow = 'ArrowLeft', Enter = 'Enter', Space = ' ', Alt = 'Alt', -- 2.39.5