gecko-dev/browser/base/content/test/keyboard/head.js
James Teh 5bada183cb Bug 1536521: Use a capturing listener for PanelMultiView's keydown handler. r=Gijs
PanelMultiView adds the keydown handler on the window so that it handles key presses when a panel appears but doesn't get focus, as happens when a button to open a panel is clicked with the mouse.
However, this means the listener is on an ancestor of the panel, which means that handlers such as ToolbarKeyboardNavigator are deeper in the tree.
Previously, PanelMultiView used a bubbling (default) listener.
This meant that ToolbarKeyboardNavigator handled the event first, causing it to interfere when a panel opened within the toolbar; e.g. the Library menu.
To fix this, use a capturing listener for PanelMultiView so it gets the event first.

Differential Revision: https://phabricator.services.mozilla.com/D24848

--HG--
extra : moz-landing-system : lando
2019-03-26 10:33:11 +00:00

18 lines
587 B
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Force focus to an element that isn't focusable.
* Toolbar buttons aren't focusable because if they were, clicking them would
* focus them, which is undesirable. Therefore, they're only made focusable
* when a user is navigating with the keyboard. This function forces focus as
* is done during toolbar keyboard navigation.
*/
function forceFocus(aElem) {
aElem.setAttribute("tabindex", "-1");
aElem.focus();
aElem.removeAttribute("tabindex");
}