Bug 1378016 - Fix keyboard navigation and selection on 'recent bookmarks'. r=Gijs
MozReview-Commit-ID: GJ7vRPz8zuo
--- 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.
*