diff --git a/public/js/app.js b/public/js/app.js index 4741b4c..dd7fb19 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -25,7 +25,7 @@ document.addEventListener('alpine:init', () => { return; if (currentWord === this.currentWord) { /* Show previous items, if any. */ - this.open = true; + this.open = this.items.length > 0; return; } this.currentWord = currentWord; @@ -35,12 +35,13 @@ document.addEventListener('alpine:init', () => { if (!response.ok) { this.items = []; + this.open = false; return; } this.activeItem = null; this.items = await response.json(); - this.open = true; + this.open = this.items.length > 0; }, async fetchSuggestionsOnInput(evt) { diff --git a/templates/_search.html.ep b/templates/_search.html.ep index 8d9b3fb..3cd3b0f 100644 --- a/templates/_search.html.ep +++ b/templates/_search.html.ep @@ -16,9 +16,7 @@ @keydown.up.prevent="moveActiveItemBackward" @keydown.down.prevent="moveActiveItemForward" @keydown.escape="open = false"> -