From 8bc5deb75b7954f0d0c7eac4f10541bfa381fda0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 12 Dec 2018 14:48:30 -0500 Subject: [PATCH] LP1806087 Search form focus fixes Signed-off-by: Bill Erickson --- .../src/app/staff/catalog/search-form.component.ts | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts index dc4c97687c..a558011f61 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts @@ -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(); } /** -- 2.11.0