feat: focus when opening dropdown

This commit is contained in:
JovannMC 2025-05-28 22:14:40 +03:00
parent 70862a5abf
commit 35a97920aa
No known key found for this signature in database
1 changed files with 22 additions and 4 deletions

View File

@ -216,6 +216,23 @@
}
};
const clickDropdown = () => {
open = !open;
if (open) {
setTimeout(() => {
if (dropdownMenu) {
const searchInput = dropdownMenu.querySelector(
"#format-search",
) as HTMLInputElement;
if (searchInput) {
searchInput.focus();
searchInput.select();
}
}
}, 0); // let dropdown open first
}
};
onMount(() => {
const handleClickOutside = (e: MouseEvent) => {
if (dropdown && !dropdown.contains(e.target as Node)) {
@ -248,10 +265,9 @@
bind:this={dropdown}
>
<button
class="font-display w-full justify-center overflow-hidden relative cursor-pointer px-3 py-3.5 bg-button {disabled
? 'opacity-50 cursor-auto'
: 'cursor-pointer'} flex items-center rounded-full focus:!outline-none"
onclick={() => (open = !open)}
class="relative flex items-center justify-center w-full font-display px-3 py-3.5 bg-button rounded-full overflow-hidden cursor-pointer focus:!outline-none
{disabled ? 'opacity-50 cursor-auto' : 'cursor-pointer'}"
onclick={() => clickDropdown()}
onmouseenter={() => (hover = true)}
onmouseleave={() => (hover = false)}
{disabled}
@ -311,6 +327,8 @@
bind:value={searchQuery}
oninput={handleSearch}
onfocus={() => {}}
id="format-search"
autocomplete="off"
/>
<span
class="absolute left-4 top-1/2 -translate-y-1/2 flex items-center"