Prevent auto-focus on search suggestions
authorAlexander Ebert <ebert@woltlab.com>
Sat, 1 Aug 2020 17:28:55 +0000 (19:28 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 1 Aug 2020 17:28:55 +0000 (19:28 +0200)
Closes #3263

wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Input.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Page.js

index 0abfac00d1df1c18fd5f3f08bf358b5cd4b9d046..245824f03da7ecbef032138ccd5658851a3817b6 100644 (file)
@@ -44,6 +44,7 @@ define(['Ajax', 'Core', 'EventKey', 'Dom/Util', 'Ui/SimpleDropdown'], function(A
                                        className: '',
                                        interfaceName: 'wcf\\data\\ISearchAction'
                                },
+                               autoFocus: true,
                                callbackDropdownInit: null,
                                callbackSelect: null,
                                delay: 500,
@@ -109,7 +110,7 @@ define(['Ajax', 'Core', 'EventKey', 'Dom/Util', 'Ui/SimpleDropdown'], function(A
                 */
                _keyup: function(event) {
                        // handle dropdown keyboard navigation
-                       if (this._activeItem !== null) {
+                       if (this._activeItem !== null || !this._options.autoFocus) {
                                if (UiSimpleDropdown.isOpen(this._dropdownContainerId)) {
                                        if (EventKey.ArrowUp(event)) {
                                                event.preventDefault();
@@ -210,15 +211,17 @@ define(['Ajax', 'Core', 'EventKey', 'Dom/Util', 'Ui/SimpleDropdown'], function(A
                 * @protected
                 */
                _keyboardNextItem: function() {
-                       this._activeItem.classList.remove('active');
+                       var nextItem;
                        
-                       if (this._activeItem.nextElementSibling) {
-                               this._activeItem = this._activeItem.nextElementSibling;
-                       }
-                       else {
-                               this._activeItem = this._list.children[0];
+                       if (this._activeItem !== null) {
+                               this._activeItem.classList.remove('active');
+                               
+                               if (this._activeItem.nextElementSibling) {
+                                       nextItem = this._activeItem.nextElementSibling;
+                               }
                        }
                        
+                       this._activeItem = nextItem || this._list.children[0];
                        this._activeItem.classList.add('active');
                },
                
@@ -228,15 +231,17 @@ define(['Ajax', 'Core', 'EventKey', 'Dom/Util', 'Ui/SimpleDropdown'], function(A
                 * @protected
                 */
                _keyboardPreviousItem: function() {
-                       this._activeItem.classList.remove('active');
+                       var nextItem;
                        
-                       if (this._activeItem.previousElementSibling) {
-                               this._activeItem = this._activeItem.previousElementSibling;
-                       }
-                       else {
-                               this._activeItem = this._list.children[this._list.childElementCount - 1];
+                       if (this._activeItem !== null) {
+                               this._activeItem.classList.remove('active');
+                               
+                               if (this._activeItem.previousElementSibling) {
+                                       nextItem = this._activeItem.previousElementSibling;
+                               }
                        }
                        
+                       this._activeItem = nextItem || this._list.children[this._list.childElementCount - 1];
                        this._activeItem.classList.add('active');
                },
                
@@ -330,7 +335,7 @@ define(['Ajax', 'Core', 'EventKey', 'Dom/Util', 'Ui/SimpleDropdown'], function(A
                                        UiSimpleDropdown.open(this._dropdownContainerId, true);
                                        
                                        // mark first item as active
-                                       if (this._list.childElementCount && ~~elData(this._list.children[0], 'object-id')) {
+                                       if (this._options.autoFocus && this._list.childElementCount && ~~elData(this._list.children[0], 'object-id')) {
                                                this._activeItem = this._list.children[0];
                                                this._activeItem.classList.add('active');
                                        }
index 7617509f0898244799fd1f9405f1b139804156f9..3822bec94267e4adcd143f9e91f3d8e5595c1e9c 100644 (file)
@@ -9,6 +9,7 @@ define(['Core', 'Dom/Traverse', 'Dom/Util', 'Ui/Screen', 'Ui/SimpleDropdown', '.
                                ajax: {
                                        className: 'wcf\\data\\search\\keyword\\SearchKeywordAction'
                                },
+                               autoFocus: false,
                                callbackDropdownInit: function(dropdownMenu) {
                                        dropdownMenu.classList.add('dropdownMenuPageSearch');