From a2bbe172938d505ff236296cde7010c8d25f6df0 Mon Sep 17 00:00:00 2001 From: Furqan A <35498810+nblogist@users.noreply.github.com> Date: Tue, 26 Mar 2024 07:20:30 +0500 Subject: [PATCH] fix(code block): fix scroll probelm (#389) Co-authored-by: Hamid Roohi --- src/components/PrettyCode.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/PrettyCode.tsx b/src/components/PrettyCode.tsx index e7663de7..f7924cd4 100644 --- a/src/components/PrettyCode.tsx +++ b/src/components/PrettyCode.tsx @@ -14,7 +14,23 @@ export default function PrettyCode({ code, language, className, customStyle }: P useEffect(() => { const listener = (ev: WheelEvent) => { - ev.stopPropagation(); + const scrollableDiv = ref.current?.children[0] as Element; + + if (ev.deltaY > 0) { + if (scrollableDiv.scrollTop >= scrollableDiv.scrollHeight - scrollableDiv.clientHeight - 1) { + // Scrollbar is at the bottom + console.log("Scrolled to end"); + } else { + ev.stopPropagation(); + } + } else { + if (scrollableDiv.scrollTop === 0) { + // Scrollbar is at the bottom + console.log("Scrolled to start"); + } else { + ev.stopPropagation(); + } + } }; ref.current?.addEventListener("wheel", listener, false); return () => {