diff --git a/js/a11y/popup.js b/js/a11y/popup.js index 07d1ee9c..39f4a9f2 100644 --- a/js/a11y/popup.js +++ b/js/a11y/popup.js @@ -89,10 +89,6 @@ export default class Popup extends Backbone.Controller { */ _addPopupLayer($popupElement) { $popupElement = $($popupElement); - const config = this.a11y.config; - if (!config._isEnabled || !config._options._isPopupManagementEnabled || $popupElement.length === 0) { - return $popupElement; - } this._floorStack.push($popupElement); this._focusStack.push($(document.activeElement)); if ($popupElement.is('dialog')) { @@ -100,6 +96,10 @@ export default class Popup extends Backbone.Controller { $popupElement[0].showModal(); return; } + const config = this.a11y.config; + if (!config._isEnabled || !config._options._isPopupManagementEnabled || $popupElement.length === 0) { + return $popupElement; + } logging.deprecated('a11y/popup opened: Use native dialog tag for', $popupElement); let $elements = $(config._options._tabbableElements).filter(config._options._tabbableElementsExcludes); const $branch = $popupElement.add($popupElement.parents()); @@ -166,10 +166,6 @@ export default class Popup extends Backbone.Controller { * @returns {Object} Returns previously active element. */ _removeLastPopupLayer() { - const config = this.a11y.config; - if (!config._isEnabled || !config._options._isPopupManagementEnabled) { - return $(document.activeElement); - } // the body layer is the first element and must always exist if (this._floorStack.length <= 1) { return; @@ -179,6 +175,10 @@ export default class Popup extends Backbone.Controller { $popupElement[0].close(); return this._focusStack.pop(); } + const config = this.a11y.config; + if (!config._isEnabled || !config._options._isPopupManagementEnabled) { + return $(document.activeElement); + } $(config._options._tabbableElements).filter(config._options._tabbableElementsExcludes).each((index, item) => { const $item = $(item); let previousTabIndex = '';