From 837f68ba5f8557fec1aaefecfefc7b5eb0453d8a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 4 Aug 2020 20:55:20 +0200 Subject: [PATCH] Prevent the incorrect focus of the close button for confirmation dialogs --- wcfsetup/install/files/js/WCF.User.js | 17 ++++++++++++++++- wcfsetup/install/files/js/WCF.js | 4 ++++ .../files/js/WoltLabSuite/Core/Ui/Dialog.js | 8 ++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.User.js b/wcfsetup/install/files/js/WCF.User.js index 183305422d..df99e45f7e 100644 --- a/wcfsetup/install/files/js/WCF.User.js +++ b/wcfsetup/install/files/js/WCF.User.js @@ -174,6 +174,11 @@ if (COMPILER_TARGET_DEFAULT) { */ _callbackFocus: null, + /** + * @var {string} + */ + _callbackCloseUuid: '', + /** * @var boolean */ @@ -193,6 +198,7 @@ if (COMPILER_TARGET_DEFAULT) { this._triggerElement = triggerElement; this._options = options; this._callbackFocus = null; + this._callbackCloseUuid = ''; this._proxy = new WCF.Action.Proxy({ showLoadingOverlay: false, @@ -259,10 +265,19 @@ if (COMPILER_TARGET_DEFAULT) { this._callbackFocus = this._maintainFocus.bind(this); } document.body.addEventListener('focus', this._callbackFocus, { capture: true }); + + this._callbackCloseUuid = WCF.System.Event.addListener('WCF.Dropdown.Interactive.Instance', 'close', (function (data) { + if (data.instance === this._dropdown) { + WCF.System.Event.removeListener('WCF.Dropdown.Interactive.Instance', 'close', this._callbackCloseUuid); + document.body.removeEventListener('focus', this._callbackFocus, { capture: true }); + } + }).bind(this)); } else { elAttr(this._button, 'aria-expanded', false); - document.body.removeEventListener('focus', this._callbackFocus); + + WCF.System.Event.removeListener('WCF.Dropdown.Interactive.Instance', 'close', this._callbackCloseUuid); + document.body.removeEventListener('focus', this._callbackFocus, { capture: true }); } return false; diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 05ffbc91f9..0c7e61dca0 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1203,6 +1203,10 @@ if (COMPILER_TARGET_DEFAULT) { close: function () { this._triggerElement.removeClass('open'); this._container.removeClass('open'); + + WCF.System.Event.fireEvent('WCF.Dropdown.Interactive.Instance', 'close', { + instance: this + }); }, /** diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js index 314912aac1..16a147f10b 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js @@ -511,6 +511,10 @@ define( } if (elAttr(data.dialog, 'aria-hidden') === 'true') { + // close existing dropdowns + UiSimpleDropdown.closeAll(); + window.WCF.Dropdown.Interactive.Handler.closeAll(); + if (_callbackFocus === null) { _callbackFocus = this._maintainFocus.bind(this); document.body.addEventListener('focus', _callbackFocus, { capture: true }); @@ -544,10 +548,6 @@ define( id: id }); } - - // close existing dropdowns - UiSimpleDropdown.closeAll(); - window.WCF.Dropdown.Interactive.Handler.closeAll(); } this.rebuild(id); -- 2.20.1