diff --git a/src/lib/components/functional/Dropdown.svelte b/src/lib/components/functional/Dropdown.svelte index f107d09..5d44f0d 100644 --- a/src/lib/components/functional/Dropdown.svelte +++ b/src/lib/components/functional/Dropdown.svelte @@ -22,8 +22,6 @@ }: Props = $props(); let open = $state(false); - let hover = $state(false); - let isUp = $state(false); let dropdown = $state(); let menuElement = $state(); let button = $state(); @@ -38,11 +36,6 @@ const select = (option: string | { value: string; label: string }) => { const selectedValue = getValue(option); - const oldIndex = options.findIndex((opt) => getValue(opt) === selected); - const newIndex = options.findIndex( - (opt) => getValue(opt) === selectedValue, - ); - isUp = oldIndex > newIndex; selected = selectedValue; onselect?.(selectedValue); toggle(); @@ -61,6 +54,15 @@ } }; + const scrollView = () => { + if (!menuElement) return; + const selectedButton = menuElement.querySelector( + "[data-selected='true']", + ) as HTMLButtonElement | null; + if (!selectedButton) return; + selectedButton.scrollIntoView({ block: "start" }); + }; + // outside clicks $effect(() => { clickHandler = (e: MouseEvent) => { @@ -82,6 +84,7 @@ document.body.appendChild(menuElement); menuElement.style.position = "fixed"; updateMenuPosition(); + requestAnimationFrame(scrollView); return () => { if (resizeHandler) @@ -111,8 +114,6 @@ ? 'rounded-xl' : 'rounded-full'} focus:!outline-none" onclick={toggle} - onmouseenter={() => (hover = true)} - onmouseleave={() => (hover = false)} {disabled} >
@@ -166,7 +167,9 @@ > {#each options as option}