fix: 搜索弹窗开启时点 burger 能正常打开菜单
关闭搜索弹窗会触发滚动恢复(window.scrollTo)发出 scroll 事件,被菜单的 closeOnScroll 立即捕获、把刚打开的菜单关掉。菜单打开后 250ms 内忽略滚动关闭, 跳过这次恢复滚动;之后用户真实滚动仍正常收起菜单。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -349,6 +349,12 @@ export function PublicLayout() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return;
|
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 closeOnOutside = (event: MouseEvent | TouchEvent) => {
|
||||||
const target = event.target as Node;
|
const target = event.target as Node;
|
||||||
if (
|
if (
|
||||||
@@ -360,7 +366,10 @@ export function PublicLayout() {
|
|||||||
}
|
}
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
const closeOnScroll = () => setOpen(false);
|
const closeOnScroll = () => {
|
||||||
|
if (Date.now() - openedAt < 250) return;
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener("mousedown", closeOnOutside);
|
document.addEventListener("mousedown", closeOnOutside);
|
||||||
document.addEventListener("touchstart", closeOnOutside);
|
document.addEventListener("touchstart", closeOnOutside);
|
||||||
|
|||||||
Reference in New Issue
Block a user