From abcca6d7f8b9c883a7c3acb1fa80aef6fe3b8a70 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Thu, 16 Jan 2025 18:27:24 +0000 Subject: [PATCH] Fix: Popup support in a11y disabled (fixes #616) --- js/a11y/popup.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 = '';