Browse Source

Bugfix: handle escape key correctly in tooltip.

Afshin Darian 7 years ago
parent
commit
416b2e8b9a
1 changed files with 10 additions and 5 deletions
  1. 10 5
      packages/tooltip/src/widget.ts

+ 10 - 5
packages/tooltip/src/widget.ts

@@ -119,18 +119,23 @@ class Tooltip extends Widget {
     if (this.isHidden || this.isDisposed) {
       return;
     }
+
+    const { node } = this;
+    const target = event.target as HTMLElement;
+
     switch (event.type) {
     case 'keydown':
-      if (this.node.contains(event.target as HTMLElement)) {
-        if ((event as KeyboardEvent).keyCode === 27) { // Escape key
-          this.dispose();
-        }
+      // If the keydown event is inside the tooltip, allow it to continue unless
+      // it is the escape key.
+      if (node.contains(target) && (event as KeyboardEvent).keyCode !== 27) {
         return;
       }
+
+      // Any other keydown event should dispose of the tooltip.
       this.dispose();
       break;
     case 'mousedown':
-      if (this.node.contains(event.target as HTMLElement)) {
+      if (node.contains(target)) {
         this.activate();
         return;
       }