Bug 1328740 - Focus popup notification panels on anchor icon keypress. r=florian
MozReview-Commit-ID: 1s0RzGJGVCX
--- a/browser/base/content/test/popupNotifications/browser_popupNotification_keyboard.js
+++ b/browser/base/content/test/popupNotifications/browser_popupNotification_keyboard.js
@@ -45,9 +45,30 @@ var tests = [
onHidden(popup) {
ok(!this.notifyObj.mainActionClicked, "mainAction was not clicked");
ok(!this.notifyObj.secondaryActionClicked, "secondaryAction was not clicked");
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
ok(!this.notifyObj.removedCallbackTriggered, "removed callback was not triggered");
this.notification.remove();
}
},
+ // Test that the space key on an anchor element focuses an active notification
+ { id: "Test#3",
+ *run() {
+ this.notifyObj = new BasicNotification(this.id);
+ this.notifyObj.anchorID = "geo-notification-icon";
+ this.notifyObj.addOptions({
+ persistent: true
+ });
+ this.notification = showNotification(this.notifyObj);
+ },
+ *onShown(popup) {
+ checkPopup(popup, this.notifyObj);
+ let anchor = document.getElementById(this.notifyObj.anchorID);
+ anchor.focus();
+ is(document.activeElement, anchor);
+ EventUtils.synthesizeKey(" ", {});
+ is(document.activeElement, popup.childNodes[0].button);
+ this.notification.remove();
+ },
+ onHidden(popup) { }
+ },
];
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -1183,16 +1183,21 @@ PopupNotifications.prototype = {
if (this.panel.state != "closed" && anchor != this._currentAnchorElement) {
this._dismissOrRemoveCurrentNotifications();
}
// Ensure we move focus into the panel because it's opened through user interaction:
this.panel.removeAttribute("noautofocus");
this._reshowNotifications(anchor);
+
+ // If the user re-selects the current notification, focus it.
+ if (anchor == this._currentAnchorElement && this.panel.firstChild) {
+ this.panel.firstChild.button.focus();
+ }
},
_reshowNotifications: function PopupNotifications_reshowNotifications(anchor, browser) {
// Mark notifications anchored to this anchor as un-dismissed
browser = browser || this.tabbrowser.selectedBrowser;
let notifications = this._getNotificationsForBrowser(browser);
notifications.forEach(function(n) {
if (n.anchorElement == anchor)