Prevent the incorrect focus of the close button for confirmation dialogs
authorAlexander Ebert <ebert@woltlab.com>
Tue, 4 Aug 2020 18:55:20 +0000 (20:55 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 4 Aug 2020 18:55:20 +0000 (20:55 +0200)
wcfsetup/install/files/js/WCF.User.js
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js

index 183305422dabf5ff0b25707ea4d063c2543823b4..df99e45f7e8e017061e864473779af1be60134c9 100644 (file)
@@ -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;
index 05ffbc91f99c6f453b81cb440b457b6bac47277f..0c7e61dca0a731911a853a769947bb5b28af6acb 100755 (executable)
@@ -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
+                       });
                },
                
                /**
index 314912aac1323f8c59be209bacf5dfc114d24e0b..16a147f10b8fe5c7e27c69c50cd303708ef523da 100644 (file)
@@ -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);