diff --git a/src/components/proxy/proxy-group.tsx b/src/components/proxy/proxy-group.tsx index 45310ab..b620c6d 100644 --- a/src/components/proxy/proxy-group.tsx +++ b/src/components/proxy/proxy-group.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { useSWRConfig } from "swr"; import { Virtuoso } from "react-virtuoso"; import { @@ -75,14 +75,14 @@ const ProxyGroup = ({ group }: Props) => { } }; - const onLocation = () => { + const onLocation = (smooth = true) => { const index = proxies.findIndex((p) => p.name === now); if (index >= 0) { virtuosoRef.current?.scrollToIndex?.({ index, align: "center", - behavior: "smooth", + behavior: smooth ? "smooth" : "auto", }); } }; @@ -110,6 +110,13 @@ const ProxyGroup = ({ group }: Props) => { checkLockRef.current = false; }; + // auto scroll to current index + useEffect(() => { + if (open) { + setTimeout(() => onLocation(false), 5); + } + }, [open]); + return ( <> setOpen(!open)} dense> @@ -131,7 +138,11 @@ const ProxyGroup = ({ group }: Props) => { - + onLocation(true)} + >