Bug 1545932 - Return focus to previous element when closing browser action. r=darktrojan a=jorgk
authorPhilipp Kewisch <mozilla@kewis.ch>
Tue, 24 Sep 2019 13:26:48 +0200
changeset 36697 0e203dc1c0338a650d2fe3b2aed097cfadfdf7f7
parent 36696 08f3db86ac9aa66ba1dfafb2dfdb70819c210255
child 36698 243c7a6e29436b4e09e06fc8b0aa57ce3ca445b7
push id394
push userclokep@gmail.com
push dateMon, 21 Oct 2019 20:22:01 +0000
reviewersdarktrojan, jorgk
bugs1545932
Bug 1545932 - Return focus to previous element when closing browser action. r=darktrojan a=jorgk
mail/components/extensions/ExtensionPopups.jsm
--- a/mail/components/extensions/ExtensionPopups.jsm
+++ b/mail/components/extensions/ExtensionPopups.jsm
@@ -53,29 +53,35 @@ class BasePopup {
       capture: true,
     });
 
     this.browser = null;
     this.browserLoaded = new Promise((resolve, reject) => {
       this.browserLoadedDeferred = { resolve, reject };
     });
     this.browserReady = this.createBrowser(viewNode, popupURL);
+    this.previousFocusedNode = this.window.document.activeElement;
 
     BasePopup.instances.get(this.window).set(extension, this);
   }
 
   static for(extension, window) {
     return BasePopup.instances.get(window).get(extension);
   }
 
   destroy() {
     this.extension.forgetOnClose(this);
 
     this.window.removeEventListener("unload", this);
 
+    if (this.previousFocusedNode) {
+      this.previousFocusedNode.focus();
+      this.previousFocusedNode = null;
+    }
+
     this.destroyed = true;
     this.browserLoadedDeferred.reject(new Error("Popup destroyed"));
     // Ignore unhandled rejections if the "attach" method is not called.
     this.browserLoaded.catch(() => {});
 
     BasePopup.instances.get(this.window).delete(this.extension);
 
     return this.browserReady.then(() => {