diff --git a/components/Switch.tsx b/components/Switch.tsx index 607889eaa..41e865f33 100644 --- a/components/Switch.tsx +++ b/components/Switch.tsx @@ -2,7 +2,7 @@ import { cn } from "@/lib/utils"; import { motion } from "framer-motion"; -import React from "react"; +import React, { useRef, useEffect } from "react"; export default function Switch({ allTag, @@ -13,8 +13,36 @@ export default function Switch({ nowTag: string; setTag: (tag: string) => void; }) { + const scrollRef = useRef(null); + + useEffect(() => { + const container = scrollRef.current; + if (!container) return; + + const isOverflowing = container.scrollWidth > container.clientWidth; + + if (!isOverflowing) { + return; + } + + const onWheel = (e: WheelEvent) => { + e.preventDefault(); + e.stopPropagation(); + container.scrollLeft += e.deltaY; + }; + + container.addEventListener("wheel", onWheel, { passive: false }); + + return () => { + container.removeEventListener("wheel", onWheel); + }; + }, []); + return ( -
+
{allTag.map((tag) => (
{nowTag === tag && (