Skip to content

Commit f855d49

Browse files
committed
Add usePreventScroll
1 parent 15e0adc commit f855d49

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

bun.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"parse-cache-control": "^1.0.1",
109109
"partial-json": "^0.1.7",
110110
"react": "^19.0.0",
111+
"react-aria": "^3.37.0",
111112
"react-dom": "^19.0.0",
112113
"react-hotkeys-hook": "^4.4.1",
113114
"rehype-sanitize": "^6.0.0",

packages/gitbook/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@tailwindcss/typography": "^0.5.16",
3838
"ai": "^4.2.2",
3939
"assert-never": "^1.2.1",
40+
"react-aria": "^3.37.0",
4041
"bun-types": "^1.1.20",
4142
"classnames": "^2.5.1",
4243
"event-iterator": "^2.0.0",

packages/gitbook/src/components/MobileMenu/MobileMenuScript.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useMobileMenuSheet } from '@/components/MobileMenu';
44
import { usePathname } from 'next/navigation';
55
import { useEffect } from 'react';
6+
import { usePreventScroll } from 'react-aria';
67

78
export function MobileMenuScript() {
89
const pathname = usePathname();
@@ -13,14 +14,10 @@ export function MobileMenuScript() {
1314
setOpen(false);
1415
}, [pathname]);
1516

16-
useEffect(() => {
17-
// If the menu is open, we add a class to the body to prevent scrolling
18-
if (open) {
19-
document.body.style.overflow = 'hidden';
20-
} else {
21-
document.body.style.overflow = 'auto';
22-
}
23-
}, [open]);
17+
// Prevent scrolling when the menu is open
18+
usePreventScroll({
19+
isDisabled: !open,
20+
});
2421

2522
return null;
2623
}

0 commit comments

Comments
 (0)