From 2b9ab9eb2c6d1f45c4582bc75ee588e849fdae5f Mon Sep 17 00:00:00 2001 From: TerryM Date: Sat, 30 May 2026 03:04:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E6=97=B6=E7=82=B9=20burger=20=E8=83=BD?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E6=89=93=E5=BC=80=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关闭搜索弹窗会触发滚动恢复(window.scrollTo)发出 scroll 事件,被菜单的 closeOnScroll 立即捕获、把刚打开的菜单关掉。菜单打开后 250ms 内忽略滚动关闭, 跳过这次恢复滚动;之后用户真实滚动仍正常收起菜单。 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/layouts/PublicLayout.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/layouts/PublicLayout.tsx b/src/layouts/PublicLayout.tsx index 684908a..7d70149 100644 --- a/src/layouts/PublicLayout.tsx +++ b/src/layouts/PublicLayout.tsx @@ -349,6 +349,12 @@ export function PublicLayout() { useEffect(() => { if (!open) return; + // Opening the menu from the burger also closes the search overlay, whose + // scroll-lock cleanup fires a programmatic scroll. Ignore scroll-to-close + // for a brief window so that restore scroll doesn't shut the menu we just + // opened; genuine user scrolls afterwards still close it. + const openedAt = Date.now(); + const closeOnOutside = (event: MouseEvent | TouchEvent) => { const target = event.target as Node; if ( @@ -360,7 +366,10 @@ export function PublicLayout() { } setOpen(false); }; - const closeOnScroll = () => setOpen(false); + const closeOnScroll = () => { + if (Date.now() - openedAt < 250) return; + setOpen(false); + }; document.addEventListener("mousedown", closeOnOutside); document.addEventListener("touchstart", closeOnOutside);