]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9504 Support ESC keyboard shortcut to skip onboarding tuto from anywhere on...
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 20 Oct 2017 14:40:03 +0000 (16:40 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 20 Oct 2017 15:44:55 +0000 (08:44 -0700)
server/sonar-web/src/main/js/apps/tutorials/onboarding/Onboarding.js

index ad825f28a364bf402f0105e7cf0581ef56495b7a..5a1ea7dcaa6178a02fd490ab4665d1956acb6217 100644 (file)
@@ -21,7 +21,6 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import Helmet from 'react-helmet';
-import key from 'keymaster';
 import TokenStep from './TokenStep';
 import OrganizationStep from './OrganizationStep';
 import AnalysisStep from './AnalysisStep';
@@ -72,28 +71,26 @@ export default class Onboarding extends React.PureComponent {
 
   componentDidMount() {
     this.mounted = true;
-    this.attachShortcuts();
+
+    // useCapture = true to receive the event before inputs
+    window.addEventListener('keydown', this.onKeyDown, true);
+
     if (!this.props.currentUser.isLoggedIn) {
       handleRequiredAuthentication();
     }
   }
 
   componentWillUnmount() {
+    window.removeEventListener('keydown', this.onKeyDown, true);
     this.mounted = false;
-    this.detachShortcuts();
   }
 
-  attachShortcuts() {
-    key.setScope('onboarding');
-    key('esc', 'onboarding', () => {
+  onKeyDown = (event /*: KeyboardEvent */) => {
+    // ESC key
+    if (event.keyCode === 27) {
       this.finishOnboarding();
-      return false;
-    });
-  }
-
-  detachShortcuts() {
-    key.deleteScope('onboarding');
-  }
+    }
+  };
 
   finishOnboarding = () => {
     this.setState({ skipping: true });