From 613e77e43f9974affb7bdaa1ecc8737030f8df9d Mon Sep 17 00:00:00 2001 From: Lim Chee Aun <cheeaun@gmail.com> Date: Mon, 30 Jan 2023 19:48:33 +0800 Subject: [PATCH] Got to be picky about the smooth vs jump scroll --- src/components/media-modal.jsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/media-modal.jsx b/src/components/media-modal.jsx index 9d246152..f9b5ef63 100644 --- a/src/components/media-modal.jsx +++ b/src/components/media-modal.jsx @@ -22,13 +22,16 @@ function MediaModal({ useLayoutEffect(() => { carouselFocusItem.current?.scrollIntoView(); }, []); + const prevStatusID = useRef(statusID); useEffect(() => { const scrollLeft = index * carouselRef.current.clientWidth; + const differentStatusID = prevStatusID.current !== statusID; + if (differentStatusID) prevStatusID.current = statusID; carouselRef.current.scrollTo({ left: scrollLeft, - behavior: 'smooth', + behavior: differentStatusID ? 'auto' : 'smooth', }); - }, [index]); + }, [index, statusID]); const [showControls, setShowControls] = useState(true);