File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ const fakeScrollableStyle: CSSProperties = {
16
16
17
17
// Example 1: useLockedBody as useState()
18
18
export default function App ( ) {
19
- const [ locked , setLocked ] = useLockedBody ( )
19
+ const [ locked , setLocked ] = useLockedBody ( false , 'root' )
20
20
21
21
const toggleLocked = ( ) => {
22
22
setLocked ( ! locked )
@@ -39,7 +39,7 @@ export function App2() {
39
39
setLocked ( ! locked )
40
40
}
41
41
42
- useLockedBody ( locked )
42
+ useLockedBody ( locked , 'root' )
43
43
44
44
return (
45
45
< div style = { fakeScrollableStyle } >
Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ import { useIsomorphicLayoutEffect } from '..'
4
4
5
5
type UseLockedBodyOutput = [ boolean , ( locked : boolean ) => void ]
6
6
7
- function useLockedBody ( initialLocked = false ) : UseLockedBodyOutput {
7
+ function useLockedBody (
8
+ initialLocked = false ,
9
+ rootId = '___gatsby' , // Default to `___gatsby` to not introduce breaking change
10
+ ) : UseLockedBodyOutput {
8
11
const [ locked , setLocked ] = useState ( initialLocked )
9
12
10
13
// Do the side effect before render
@@ -21,7 +24,7 @@ function useLockedBody(initialLocked = false): UseLockedBodyOutput {
21
24
document . body . style . overflow = 'hidden'
22
25
23
26
// Get the scrollBar width
24
- const root = document . getElementById ( '___gatsby' ) // or root
27
+ const root = document . getElementById ( rootId ) // or root
25
28
const scrollBarWidth = root ? root . offsetWidth - root . scrollWidth : 0
26
29
27
30
// Avoid width reflow
You can’t perform that action at this time.
0 commit comments