Skip to content

Commit

Permalink
fix issue with scrolling after closing modal (#2823)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinicz authored Dec 5, 2024
1 parent 3f5d1b0 commit ef32dc5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/dialog/useBodyNoScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export function useBodyNoScroll(overlayRef: {current: HTMLDivElement | null}) {

const initialBodyClassList = body.classList.value;
const initialBodyStyleTop = body.style.top;
const initialScrollY = window.scrollY;

if (initialBodyClassList.includes(NO_SCROLL_CLASS)) {
return;
}

body.style.top = `-${window.scrollY}px`;
body.style.top = `-${initialScrollY}px`;
body.classList.add(NO_SCROLL_CLASS);

const cleanup = () => {
Expand All @@ -30,7 +31,7 @@ export function useBodyNoScroll(overlayRef: {current: HTMLDivElement | null}) {

body.style.top = initialBodyStyleTop;
body.className = initialBodyClassList;
window.scrollTo(0, scrollY);
window.scrollTo(0, initialScrollY);
};

// @ts-ignore TS2322
Expand Down

0 comments on commit ef32dc5

Please sign in to comment.