Explorar o código

Fix a bug since merging arrow navigation between buttons in Dialog (#10349) (#10395)

* Fix #10394

* Fix linux test
Jay Ahn %!s(int64=3) %!d(string=hai) anos
pai
achega
163bb9340d
Modificáronse 1 ficheiros con 24 adicións e 18 borrados
  1. 24 18
      packages/apputils/src/dialog.tsx

+ 24 - 18
packages/apputils/src/dialog.tsx

@@ -305,33 +305,39 @@ export class Dialog<T> extends Widget {
       case 37: {
         // Left arrow
         const activeEl = document.activeElement;
-        let idx = this._buttonNodes.indexOf(activeEl as HTMLElement) - 1;
 
-        // Handle a left arrows on the first button
-        if (idx < 0) {
-          idx = this._buttonNodes.length - 1;
-        }
+        if (activeEl instanceof HTMLButtonElement) {
+          let idx = this._buttonNodes.indexOf(activeEl as HTMLElement) - 1;
 
-        const node = this._buttonNodes[idx];
-        event.stopPropagation();
-        event.preventDefault();
-        node.focus();
+          // Handle a left arrows on the first button
+          if (idx < 0) {
+            idx = this._buttonNodes.length - 1;
+          }
+
+          const node = this._buttonNodes[idx];
+          event.stopPropagation();
+          event.preventDefault();
+          node.focus();
+        }
         break;
       }
       case 39: {
         // Right arrow
         const activeEl = document.activeElement;
-        let idx = this._buttonNodes.indexOf(activeEl as HTMLElement) + 1;
 
-        // Handle a right arrows on the last button
-        if (idx == this._buttons.length) {
-          idx = 0;
-        }
+        if (activeEl instanceof HTMLButtonElement) {
+          let idx = this._buttonNodes.indexOf(activeEl as HTMLElement) + 1;
 
-        const node = this._buttonNodes[idx];
-        event.stopPropagation();
-        event.preventDefault();
-        node.focus();
+          // Handle a right arrows on the last button
+          if (idx == this._buttons.length) {
+            idx = 0;
+          }
+
+          const node = this._buttonNodes[idx];
+          event.stopPropagation();
+          event.preventDefault();
+          node.focus();
+        }
         break;
       }
       case 9: {