diff --git a/js/a11y/popup.js b/js/a11y/popup.js index 39f4a9f2..76293b72 100644 --- a/js/a11y/popup.js +++ b/js/a11y/popup.js @@ -1,5 +1,6 @@ import Adapt from 'core/js/adapt'; import logging from '../logging'; +import wait from 'core/js/wait'; /** * Tabindex and aria-hidden manager for popups. @@ -146,12 +147,16 @@ export default class Popup extends Backbone.Controller { * Close the last popup on the stack, restoring tabindex and aria-hidden * attributes. * - * @param {Object} [$focusElement] Element at which to move focus. + * @param {Object} [$forceFocusElement] Element at which to move focus. * @returns {Object} Returns `a11y._popup`. */ - closed($focusElement, silent) { + async closed($forceFocusElement, silent) { + if (!silent) { + Adapt.trigger('popup:closing'); + await wait.queue(); + } const $previousFocusElement = this._removeLastPopupLayer(); - $focusElement = $focusElement || $previousFocusElement || $('body'); + const $focusElement = $forceFocusElement || $previousFocusElement || $('body'); if (!silent) { Adapt.trigger('popup:closed', $focusElement, true); } diff --git a/js/views/notifyPopupView.js b/js/views/notifyPopupView.js index 62803e7a..ca6daf5b 100644 --- a/js/views/notifyPopupView.js +++ b/js/views/notifyPopupView.js @@ -126,8 +126,6 @@ export default class NotifyPopupView extends Backbone.View { await this.addSubView(); // Add to the list of open popups this.notify.stack.push(this); - // Keep focus from previous action - this.$previousActiveElement = $(document.activeElement); Adapt.trigger('notify:opened', this); this.$el.imageready(this.onLoaded.bind(this)); } @@ -203,7 +201,7 @@ export default class NotifyPopupView extends Backbone.View { a11y.scrollEnable('body'); $('html').removeClass('notify'); // Return focus to previous active element - a11y.popupClosed(this.$previousActiveElement); + await a11y.popupClosed(); // Return reference to the notify view Adapt.trigger('notify:closed', this); }