Skip to content

Commit ef32dc5

Browse files
authored
fix issue with scrolling after closing modal (#2823)
1 parent 3f5d1b0 commit ef32dc5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/components/dialog/useBodyNoScroll.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ export function useBodyNoScroll(overlayRef: {current: HTMLDivElement | null}) {
1616

1717
const initialBodyClassList = body.classList.value;
1818
const initialBodyStyleTop = body.style.top;
19+
const initialScrollY = window.scrollY;
1920

2021
if (initialBodyClassList.includes(NO_SCROLL_CLASS)) {
2122
return;
2223
}
2324

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

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

3132
body.style.top = initialBodyStyleTop;
3233
body.className = initialBodyClassList;
33-
window.scrollTo(0, scrollY);
34+
window.scrollTo(0, initialScrollY);
3435
};
3536

3637
// @ts-ignore TS2322

0 commit comments

Comments
 (0)