bugfixing search bar: select first row

This commit is contained in:
MuslemRahimi 2025-03-07 12:14:23 +01:00
parent 8a748e281c
commit e8164b4bfa

View File

@ -4,6 +4,7 @@
import Search from "lucide-svelte/icons/search"; import Search from "lucide-svelte/icons/search";
import { goto } from "$app/navigation"; import { goto } from "$app/navigation";
import { Combobox } from "bits-ui"; import { Combobox } from "bits-ui";
import { tick } from "svelte";
let searchHistory = []; let searchHistory = [];
let updatedSearchHistory = []; let updatedSearchHistory = [];
@ -154,6 +155,7 @@
async function search() { async function search() {
isLoading = true; isLoading = true;
clearTimeout(timeoutId); // Clear any existing timeout clearTimeout(timeoutId); // Clear any existing timeout
if (!inputValue.trim()) { if (!inputValue.trim()) {
@ -229,6 +231,7 @@
$: { $: {
if (searchBarModalChecked === true && typeof window !== "undefined") { if (searchBarModalChecked === true && typeof window !== "undefined") {
console.log("open");
if ($screenWidth > 640) { if ($screenWidth > 640) {
inputElement.focus(); inputElement.focus();
} }
@ -277,6 +280,17 @@
search(); search();
} }
} }
$: if (showSuggestions && searchBarData?.length && touchedInput) {
tick().then(() => {
const input = document.getElementById("combobox-input");
if (input) {
input.dispatchEvent(
new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }),
);
}
});
}
</script> </script>
<div class="hidden sm:block w-full sm:max-w-[600px]"> <div class="hidden sm:block w-full sm:max-w-[600px]">