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 b8a212cd174f81994e3cdb5adc4226b5dfc531d3
parent 618383 26516ba270816a6cc90f5c42a9b66701369a551f
child 640498 7f33114ea69b8ba61cf506b84e87acd9fb7acb05
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.
    *