Skip to content

Commit f03ada3

Browse files
authored
Require allowScrollWithin ref on useScrollLock (#41)
1 parent 80c587c commit f03ada3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

packages/components/src/Modal/ModalPortal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export interface ModalPortalProps {
3737

3838
export const ModalPortal: FC<ModalPortalProps> = ({ portalRef, children }) => {
3939
const el = useRef(document.createElement('div'))
40-
useScrollLock(false, portalRef)
40+
const ref = useRef<HTMLDivElement>(null)
41+
const refToUse = portalRef || ref
42+
43+
useScrollLock(refToUse)
4144

4245
useEffect(() => {
4346
const modalRoot = getModalRoot()
@@ -52,7 +55,7 @@ export const ModalPortal: FC<ModalPortalProps> = ({ portalRef, children }) => {
5255
}, [el])
5356

5457
const content = (
55-
<InvisiBox ref={portalRef} zIndex={CustomizableModalAttributes.zIndex}>
58+
<InvisiBox ref={refToUse} zIndex={CustomizableModalAttributes.zIndex}>
5659
{children}
5760
</InvisiBox>
5861
)

packages/components/src/utils/useScrollLock.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
MIT License
44
55
Copyright (c) 2019 Looker Data Sciences, Inc.
6-
6+
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
99
in the Software without restriction, including without limitation the rights
1010
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
copies of the Software, and to permit persons to whom the Software is
1212
furnished to do so, subject to the following conditions:
13-
13+
1414
The above copyright notice and this permission notice shall be included in all
1515
copies or substantial portions of the Software.
16-
16+
1717
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -27,8 +27,8 @@
2727
import { RefObject, useEffect } from 'react'
2828

2929
export function useScrollLock(
30-
disabled?: boolean,
31-
allowScrollWithin?: RefObject<HTMLElement | null>
30+
allowScrollWithin: RefObject<HTMLElement | null>,
31+
disabled = false
3232
) {
3333
useEffect(() => {
3434
let scrollTop = window.scrollY

0 commit comments

Comments
 (0)