From: Bill Erickson Date: Wed, 12 Dec 2018 19:48:30 +0000 (-0500) Subject: LP#1806087 Search form focus fixes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e0c99b6d35677e670d7678a06d98735683bb1087;p=working%2FEvergreen.git LP#1806087 Search form focus fixes Signed-off-by: Bill Erickson --- 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(); } /**