Bug 1645643 - [macOS] Force focus when a click event is registered on a recipient pill. Workaround for bug 1645916. r=Paenglab a=wsmwk
authorAlessandro Castellani <alessandro@thunderbird.net>
Tue, 16 Jun 2020 21:11:29 +0200
changeset 39412 e431355d0d285ec02da2478c106c00c5f524c1d7
parent 39411 931823eeff65b826ca34af4b2ab378c94234004d
child 39413 937f289bd94db87a3844084961dec4e6ec44cffe
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersPaenglab, wsmwk
bugs1645643, 1645916
Bug 1645643 - [macOS] Force focus when a click event is registered on a recipient pill. Workaround for bug 1645916. r=Paenglab a=wsmwk
mail/base/content/mailWidgets.js
--- a/mail/base/content/mailWidgets.js
+++ b/mail/base/content/mailWidgets.js
@@ -2476,20 +2476,21 @@
             copyEmailNewsAddress(pill);
             this.removeSelectedPills(pill);
           }
           break;
       }
     }
 
     /**
-     * Handle the selection and focus of the pill elements on mouse events.
+     * Handle the selection and focus of recipient pill elements on mouse click
+     * and spacebar keypress events.
      *
-     * @param {XULElement} pill - The mail-address-pill element.
-     * @param {Event} event - The DOM Event.
+     * @param {HTMLElement} pill - The <mail-address-pill> element, event target.
+     * @param {Event} event - A DOM click or keypress Event.
      */
     checkSelected(pill, event) {
       if (pill.isEditing) {
         return;
       }
 
       if (pill.hasAttribute("selected") && event.button == 2) {
         emailAddressPillOnPopupShown();
@@ -2497,16 +2498,21 @@
       }
 
       if (!event.ctrlKey && !event.metaKey && event.key != " ") {
         this.clearSelected();
       }
 
       pill.toggleAttribute("selected");
 
+      // We need to force the focus on a pill that receives a click event
+      // (or a spacebar keypress), as macOS doesn't automatically move the focus
+      // on this custom element (bug 1645643, bug 1645916).
+      pill.focus();
+
       // Update the options in the context menu only after the pills were
       // selected and if the event was a right click.
       if (event.button == 2) {
         emailAddressPillOnPopupShown();
       }
     }
 
     /**