From 9ef34359d8ac32674c28825b91b6aa2877e63552 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Tue, 20 May 2025 01:24:42 +0200 Subject: [PATCH] wip --- src/components/tools/VirtualSelect.svelte | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/tools/VirtualSelect.svelte b/src/components/tools/VirtualSelect.svelte index 9e906c84..2822f9ca 100644 --- a/src/components/tools/VirtualSelect.svelte +++ b/src/components/tools/VirtualSelect.svelte @@ -166,16 +166,18 @@ updateVisibleItems(); } - // Initialize container size observer and autofocus - onMount(() => { + // Initialize container size observer and autofocus fallback + onMount(async () => { if (container) { const resizeObserver = new ResizeObserver(updateVisibleCount); resizeObserver.observe(container); - if (autofocus && inputElement) { - inputElement.focus(); - } return () => resizeObserver.disconnect(); } + // Fallback autofocus with tick to ensure inputElement is bound + if (autofocus && inputElement) { + await tick(); + inputElement.focus(); + } }); // Get display text for the input @@ -204,6 +206,7 @@ class="w-full bg-transparent focus:outline-none {selected ? 'text-black' : 'text-gray-700'}" + {autofocus} on:focus={handleInputFocus} on:input={handleInput} on:keydown={(e) => {