Skip to content

Commit

Permalink
fix(code block): fix scroll probelm (#389)
Browse files Browse the repository at this point in the history
Co-authored-by: Hamid Roohi <[email protected]>
  • Loading branch information
nblogist and hamidroohi92 authored Mar 26, 2024
1 parent a3841da commit a2bbe17
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/PrettyCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit a2bbe17

Please sign in to comment.