Bug 1378016 - Fix keyboard navigation and selection on 'recent bookmarks'. r=Gijs draft
authorErica Wright <ewright@mozilla.com>
Mon, 31 Jul 2017 09:47:19 -0400
changeset 619750 b8a212cd174f
parent 618383 26516ba27081
child 640498 7f33114ea69b
push id71794
push userbmo:ewright@mozilla.com
push dateWed, 02 Aug 2017 14:06:26 +0000
reviewersGijs
bugs1378016
milestone56.0a1
Bug 1378016 - Fix keyboard navigation and selection on 'recent bookmarks'. r=Gijs MozReview-Commit-ID: GJ7vRPz8zuo
browser/components/customizableui/PanelMultiView.jsm
--- a/browser/components/customizableui/PanelMultiView.jsm
+++ b/browser/components/customizableui/PanelMultiView.jsm
@@ -1016,22 +1016,20 @@ this.PanelMultiView = class {
       this._keyNavigationMap.set(view, navMap);
     }
 
     let buttons = navMap.buttons;
     if (!buttons || !buttons.length) {
       buttons = navMap.buttons = this._getNavigableElements(view);
       // Set the 'tabindex' attribute on the buttons to make sure they're focussable.
       for (let button of buttons) {
-        if (button.classList.contains("subviewbutton-back"))
-          continue;
-        // If we've been here before, forget about it!
-        if (button.hasAttribute("tabindex"))
-          break;
-        button.setAttribute("tabindex", 0);
+        if (!button.classList.contains("subviewbutton-back") &&
+            !button.hasAttribute("tabindex")) {
+          button.setAttribute("tabindex", 0);
+        }
       }
     }
     if (!buttons.length)
       return;
 
     let stop = () => {
       event.stopPropagation();
       event.preventDefault();
@@ -1072,24 +1070,31 @@ this.PanelMultiView = class {
           break;
         }
         // If the current button is _not_ one that points to a subview, pressing
         // the arrow key shouldn't do anything.
         if (!navMap.selected || !buttons[navMap.selected].classList.contains("subviewbutton-nav"))
           break;
         // Fall-through...
       }
+      case "Space":
       case "Enter": {
         let button = buttons[navMap.selected];
         if (!button)
           break;
         stop();
-        // Unfortunately, 'tabindex' doesn't not execute the default action, so
+
+        // Unfortunately, 'tabindex' doesn't execute the default action, so
         // we explicitly do this here.
-        button.click();
+        // We are sending a command event and then a click event.
+        // This is done in order to mimic a "real" mouse click event.
+        // The command event executes the action, then the click event closes the menu.
+        button.doCommand();
+        let clickEvent = new event.target.ownerGlobal.MouseEvent("click", {"bubbles": true});
+        button.dispatchEvent(clickEvent);
         break;
       }
     }
   }
 
   /**
    * Clear all traces of keyboard navigation happening right now.
    *