Prevent the focus being trapped if the user intentionally clicks outside
authorAlexander Ebert <ebert@woltlab.com>
Thu, 20 Aug 2020 22:28:22 +0000 (00:28 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 20 Aug 2020 22:28:22 +0000 (00:28 +0200)
Clicking on a link or button outside of the overlay caused the browser to close the drop-down and shift the focus on the menu element.

wcfsetup/install/files/js/WCF.User.js

index 975554177a9d91ae82b9eea62a2a51fb210d70bd..2b5a12225fd765f598f997d312472cde75ee8d90 100644 (file)
@@ -455,6 +455,11 @@ if (COMPILER_TARGET_DEFAULT) {
                 * @param {Event} event
                 */
                _maintainFocus: function(event) {
+                       // Ignore a focus shift that was not the result of a keyboard interaction.
+                       if (document.activeElement && !document.activeElement.classList.contains('focus-visible')) {
+                               return;
+                       }
+                       
                        var dropdown = this._dropdown.getContainer()[0];
                        
                        if (!dropdown.contains(event.target)) {