From 5c009d74fed88dbc9e400389bdc56ee0b79d1f65 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Mon, 22 Jan 2024 16:04:58 +0100 Subject: [PATCH] Search: enable click only result --- src/lib/components/Search.svelte | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/components/Search.svelte b/src/lib/components/Search.svelte index 6e8ce12..abc11ec 100644 --- a/src/lib/components/Search.svelte +++ b/src/lib/components/Search.svelte @@ -36,9 +36,12 @@ onMount(() => { scroller.parentNode.style.display= 'none' }) scroll + let items = document.querySelectorAll(".matched-recipe"); + items = [...new Set(items)] // make unique as seasonal mediascroller can lead to duplicates // if only one result and click_only_result is true, click it - if(click_only_result && scrollers_with_results.length == 1 && scrollers_with_results[0].querySelector(".matched-recipe").length == 1){ - scrollers_with_results[0].querySelector(".matched-recipe").click() + if(click_only_result && scrollers_with_results.length == 1 && items.length == 1){ + // add '/rezepte' to history to not force-redirect back to recipe if going back + items[0].click(); } // if scrollers with results are presenet scroll first result into view /*if(scrollers_with_results.length > 0){