From bf21610576dc2991495004b634802fbc21ab9777 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Vuotto Date: Mon, 28 Apr 2025 15:58:00 +0000 Subject: [PATCH] site: bind search component open to items.length --- public/js/app.js | 5 +++-- templates/_search.html.ep | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) 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"> -