LP1806087 Search form focus fixes
authorBill Erickson <berickxx@gmail.com>
Wed, 12 Dec 2018 19:48:30 +0000 (14:48 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 10 Jan 2019 17:23:51 +0000 (12:23 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts

index dc4c976..a558011 100644 (file)
@@ -51,27 +51,36 @@ export class SearchFormComponent implements OnInit, AfterViewInit {
         setTimeout(() => {
 
             // Apply a tab if none was already specified
-            if (this.searchTab) { return; }
-
-            // Assumes that only one type of search will be searchable
-            // at any given time.
-            if (this.context.marcSearch.isSearchable()) {
-                this.searchTab = 'marc';
-            } else if (this.context.identSearch.isSearchable()) {
-                this.searchTab = 'ident';
-            } else if (this.context.browseSearch.isSearchable()) {
-                this.searchTab = 'browse';
-            } else {
-                // Default tab
-                this.searchTab = 'term';
-                this.refreshCopyLocations();
+            if (!this.searchTab) {
+                // Assumes that only one type of search will be searchable
+                // at any given time.
+                if (this.context.marcSearch.isSearchable()) {
+                    this.searchTab = 'marc';
+                } else if (this.context.identSearch.isSearchable()) {
+                    this.searchTab = 'ident';
+                } else if (this.context.browseSearch.isSearchable()) {
+                    this.searchTab = 'browse';
+                } else {
+                    // Default tab
+                    this.searchTab = 'term';
+                    this.refreshCopyLocations();
+                }
             }
+
+            this.focusTabInput();
         });
     }
 
     onTabChange(evt: NgbTabChangeEvent) {
         this.searchTab = evt.nextId;
 
+        // Focus after tab-change event has a chance to complete
+        // or the tab body and its input won't exist yet and no
+        // elements will be focus-able.
+        setTimeout(() => this.focusTabInput());
+    }
+
+    focusTabInput() {
         // Select a DOM node to focus when the tab changes.
         let selector;
         switch (this.searchTab) {
@@ -89,10 +98,7 @@ export class SearchFormComponent implements OnInit, AfterViewInit {
                 selector = '#first-query-input';
         }
 
-        // Call focus after tab-change event has a chance to complete
-        // or the tab body and its input won't exist yet.
-        setTimeout(() => 
-            this.renderer.selectRootElement(selector).focus());
+        this.renderer.selectRootElement(selector).focus();
     }
 
     /**