From 801d882dc1101152664357ff65ea4a726adfec19 Mon Sep 17 00:00:00 2001 From: Juliet Date: Fri, 30 Jan 2026 00:52:01 +0100 Subject: [PATCH] fix dropdown zoom position --- src/components/dropdown.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/dropdown.tsx b/src/components/dropdown.tsx index 3ab651d..2685e3e 100644 --- a/src/components/dropdown.tsx +++ b/src/components/dropdown.tsx @@ -104,7 +104,7 @@ export const DropdownMenu = (props: { const ctx = useContext(MenuContext); const [menu, setMenu] = createSignal(); const [menuButton, setMenuButton] = createSignal(); - const [buttonRect, setButtonRect] = createSignal(); + const [buttonRect, setButtonRect] = createSignal<{ bottom: number; right: number }>(); const clickEvent = (event: MouseEvent) => { const target = event.target as Node; @@ -113,19 +113,30 @@ export const DropdownMenu = (props: { const updatePosition = () => { const rect = menuButton()?.getBoundingClientRect(); - if (rect) setButtonRect(rect); + if (rect) { + const isTouchDevice = window.matchMedia("(hover: none)").matches; + const vv = isTouchDevice ? window.visualViewport : null; + setButtonRect({ + bottom: rect.bottom + (vv?.offsetTop ?? 0), + right: rect.right + (vv?.offsetLeft ?? 0), + }); + } }; onMount(() => { window.addEventListener("click", clickEvent); window.addEventListener("scroll", updatePosition, true); window.addEventListener("resize", updatePosition); + window.visualViewport?.addEventListener("resize", updatePosition); + window.visualViewport?.addEventListener("scroll", updatePosition); }); onCleanup(() => { window.removeEventListener("click", clickEvent); window.removeEventListener("scroll", updatePosition, true); window.removeEventListener("resize", updatePosition); + window.visualViewport?.removeEventListener("resize", updatePosition); + window.visualViewport?.removeEventListener("scroll", updatePosition); }); return ( -- 2.51.2