Skip to content

Commit 2722bbe

Browse files
authored
Merge pull request #56 from Icinga/fix/search-suggestions-get-hidden-needlessly-55
Fix that search suggestions get hidden needlessly
2 parents 549100a + f42edf7 commit 2722bbe

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

asset/js/widget/BaseInput.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,8 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
805805
this.deselectTerms();
806806

807807
let input = event.target;
808-
if (! this.hasSyntaxError(input)) {
808+
if (! this.hasSyntaxError(input) && ! this.completer.isBeingCompleted(input, false)) {
809+
// Only request suggestions if the input is valid and not already being completed
809810
let value = this.readPartialTerm(input);
810811
this.complete(input, { trigger: 'script', term: { label: value } });
811812
}

asset/js/widget/Completer.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,7 @@ define(["../notjQuery"], function ($) {
220220
// If the suggestions are to be displayed due to a scripted event,
221221
// show them only if the completed input is still focused..
222222
if (document.activeElement === input) {
223-
let options = suggestions.querySelectorAll('[type="button"]');
224-
// ..and only if there are multiple options available
225-
if (options.length > 1) {
226-
this.showSuggestions(suggestions, input);
227-
}
223+
this.showSuggestions(suggestions, input);
228224
}
229225
} else {
230226
this.showSuggestions(suggestions, input);
@@ -313,7 +309,10 @@ define(["../notjQuery"], function ($) {
313309
activeElement = document.activeElement;
314310
}
315311

316-
return input === this.completedInput && this.termSuggestions.contains(activeElement);
312+
return input === this.completedInput && (
313+
(! activeElement && this.hasSuggestions())
314+
|| (activeElement && this.termSuggestions.contains(activeElement))
315+
);
317316
}
318317

319318
/**
@@ -334,12 +333,17 @@ define(["../notjQuery"], function ($) {
334333
}
335334

336335
let input = event.target;
336+
let completedInput = this.completedInput;
337337
this.suggestionKiller = setTimeout(() => {
338-
if (! this.termSuggestions.contains(document.activeElement)) {
338+
if (completedInput !== this.completedInput) {
339+
// Don't hide another input's suggestions
340+
} else if (document.activeElement !== completedInput
341+
&& ! this.termSuggestions.contains(document.activeElement)
342+
) {
339343
// Hide the suggestions if the user doesn't navigate them
340-
if (input !== this.completedInput) {
344+
if (input !== completedInput) {
341345
// Restore input if a suggestion lost focus
342-
this.suggest(this.completedInput, this.completedValue);
346+
this.suggest(completedInput, this.completedValue);
343347
}
344348

345349
this.hideSuggestions();

0 commit comments

Comments
 (0)