diff --git a/bun.lockb b/bun.lockb index 58cd51b..4eaae49 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/Switch.tsx b/components/Switch.tsx index f066307..447f04b 100644 --- a/components/Switch.tsx +++ b/components/Switch.tsx @@ -59,7 +59,24 @@ export default function Switch({ w: currentTagElement.offsetWidth, }) } - }, [nowTag, allTag]) + }, [nowTag]) + + useEffect(() => { + const currentTagElement = tagRefs.current[allTag.indexOf(nowTag)]?.current + const container = scrollRef.current + + if (currentTagElement && container) { + const containerRect = container.getBoundingClientRect() + const tagRect = currentTagElement.getBoundingClientRect() + + const scrollLeft = currentTagElement.offsetLeft - (containerRect.width - tagRect.width) / 2 + + container.scrollTo({ + left: Math.max(0, scrollLeft), + behavior: "smooth", + }) + } + }, [nowTag]) return (