aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/components/hoc
diff options
context:
space:
mode:
authorGuillaume Peoc'h <guillaume.peoch@sonarsource.com>2022-05-30 11:17:09 +0200
committersonartech <sonartech@sonarsource.com>2022-05-31 20:02:50 +0000
commita5b423674c8da134b60f464857fed2ea3df74b01 (patch)
treefc394b2715d1d8358fcd247dc8c113a6787181d2 /server/sonar-web/src/main/js/components/hoc
parent5dc735487ccaa4fd9557a2bc99b1654756c65d8d (diff)
downloadsonarqube-a5b423674c8da134b60f464857fed2ea3df74b01.tar.gz
sonarqube-a5b423674c8da134b60f464857fed2ea3df74b01.zip
SONAR-16337 Handle shortcuts and inputs when keydown
Diffstat (limited to 'server/sonar-web/src/main/js/components/hoc')
-rw-r--r--server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/components/hoc/withKeyboardNavigation.tsx4
2 files changed, 8 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx b/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx
index b4197c05a62..4ee53ee75b2 100644
--- a/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx
+++ b/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx
@@ -79,12 +79,16 @@ it('should correctly bind key events for component navigation', () => {
keydown({ code: KeyboardCodes.DownArrow });
expect(onHighlight).toBeCalledWith(COMPONENTS[0]);
+ keydown({ code: KeyboardCodes.RightArrow, metaKey: true });
+ expect(onSelect).not.toBeCalled();
keydown({ code: KeyboardCodes.RightArrow });
expect(onSelect).toBeCalledWith(COMPONENTS[0]);
keydown({ code: KeyboardCodes.Enter });
expect(onSelect).toBeCalledWith(COMPONENTS[0]);
+ keydown({ code: KeyboardCodes.LeftArrow, metaKey: true });
+ expect(onGoToParent).not.toBeCalled();
keydown({ code: KeyboardCodes.LeftArrow });
expect(onGoToParent).toBeCalled();
});
diff --git a/server/sonar-web/src/main/js/components/hoc/withKeyboardNavigation.tsx b/server/sonar-web/src/main/js/components/hoc/withKeyboardNavigation.tsx
index b92a470199e..4232c27bc57 100644
--- a/server/sonar-web/src/main/js/components/hoc/withKeyboardNavigation.tsx
+++ b/server/sonar-web/src/main/js/components/hoc/withKeyboardNavigation.tsx
@@ -20,6 +20,7 @@
import * as React from 'react';
import PageActions from '../../components/ui/PageActions';
import { getComponentMeasureUniqueKey } from '../../helpers/component';
+import { isInput, isShortcut } from '../../helpers/keyboardEventHelpers';
import { KeyboardCodes } from '../../helpers/keycodes';
import { ComponentMeasure } from '../../types/types';
import { getWrappedDisplayName } from './utils';
@@ -50,6 +51,9 @@ export default function withKeyboardNavigation<P>(
}
handleKeyDown = (event: KeyboardEvent) => {
+ if (isInput(event) || isShortcut(event)) {
+ return true;
+ }
if (event.code === KeyboardCodes.UpArrow) {
event.preventDefault();
return this.skipIfFile(this.handleHighlightPrevious);