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 { goto } from "$app/navigation";
import { Combobox } from "bits-ui";
import { tick } from "svelte";
let searchHistory = [];
let updatedSearchHistory = [];
@ -154,6 +155,7 @@
async function search() {
isLoading = true;
clearTimeout(timeoutId); // Clear any existing timeout
if (!inputValue.trim()) {
@ -229,6 +231,7 @@
$: {
if (searchBarModalChecked === true && typeof window !== "undefined") {
console.log("open");
if ($screenWidth > 640) {
inputElement.focus();
}
@ -277,6 +280,17 @@
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>
<div class="hidden sm:block w-full sm:max-w-[600px]">