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) {
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();
}
/**