Skip to content

Commit dc26883

Browse files
fix: modal body scrolling (#10157)
1 parent 4ab2f28 commit dc26883

File tree

6 files changed

+13
-56
lines changed

6 files changed

+13
-56
lines changed

src/components/ManageAccountsDrawer/components/DrawerWrapper.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ export type DrawerWrapperProps = {
77
variant?: string
88
}
99

10+
// This prevents manage accounts modal from blocking pointer events here when it's open
11+
const overrideStyles = { pointerEvents: 'auto' as const }
12+
1013
export const DrawerWrapper = ({ children, isOpen, onClose, variant }: DrawerWrapperProps) => {
1114
return (
1215
<Drawer isOpen={isOpen} size='lg' placement='right' onClose={onClose} variant={variant}>
13-
<DrawerOverlay zIndex='modal' />
14-
<DrawerContent>
16+
<DrawerOverlay zIndex='modal' style={overrideStyles} />
17+
<DrawerContent style={overrideStyles}>
1518
<DrawerCloseButton top='calc(env(safe-area-inset-top) + var(--safe-area-inset-top) + 1rem)' />
1619
{children}
1720
</DrawerContent>

src/components/MobileWalletDialog/MobileWalletDialog.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ export const MobileWalletDialog: React.FC<MobileWalletDialogProps> = ({
6969
}, [mobileWalletDialog])
7070

7171
return (
72-
<Dialog
73-
isOpen={mobileWalletDialog.isOpen}
74-
onClose={handleClose}
75-
height='auto'
76-
isDisablingPropagation={false}
77-
>
72+
<Dialog isOpen={mobileWalletDialog.isOpen} onClose={handleClose} height='auto'>
7873
<MemoryRouter>
7974
<MobileDialogRoutes defaultRoute={defaultRoute} onClose={handleClose} />
8075
</MemoryRouter>

src/components/Modal/components/Dialog.tsx

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, Modal, ModalContent, ModalOverlay, useMediaQuery } from '@chakra-ui/react'
1+
import { Modal, ModalContent, ModalOverlay, useMediaQuery } from '@chakra-ui/react'
22
import styled from '@emotion/styled'
33
import type { PropsWithChildren } from 'react'
44
import React, { useEffect, useLayoutEffect, useMemo, useState } from 'react'
@@ -16,7 +16,6 @@ export type DialogProps = {
1616
onClose: () => void
1717
height?: string
1818
isFullScreen?: boolean
19-
isDisablingPropagation?: boolean
2019
} & PropsWithChildren
2120

2221
const CustomDrawerContent = styled(Drawer.Content)`
@@ -45,7 +44,6 @@ const DialogWindow: React.FC<DialogProps> = ({
4544
height,
4645
isFullScreen,
4746
children,
48-
isDisablingPropagation = true,
4947
}) => {
5048
const [isLargerThanMd] = useMediaQuery(`(min-width: ${breakpoints['md']})`, { ssr: false })
5149
const { snapPoint, setIsOpen, isOpen: isDialogOpen } = useDialog()
@@ -75,30 +73,6 @@ const DialogWindow: React.FC<DialogProps> = ({
7573
setIsOpen(isOpen)
7674
}, [isOpen, setIsOpen])
7775

78-
// This is a workaround to prevent the body to be pointer-events: none when the dialog is open if isDisablingPropagation is false
79-
useEffect(() => {
80-
if (!isDialogOpen) return
81-
if (isDisablingPropagation) return
82-
83-
const originalPointerEvents = document.body.style.pointerEvents
84-
const focusGuardedElements = document.querySelectorAll<HTMLElement>('*[data-radix-focus-guard]')
85-
86-
const raf = window.requestAnimationFrame(() => {
87-
document.body.style.pointerEvents = 'auto'
88-
focusGuardedElements.forEach(element => {
89-
element.style.pointerEvents = 'auto'
90-
})
91-
})
92-
93-
return () => {
94-
window.cancelAnimationFrame(raf)
95-
document.body.style.pointerEvents = originalPointerEvents
96-
focusGuardedElements.forEach(element => {
97-
element.style.pointerEvents = 'inherit'
98-
})
99-
}
100-
}, [isDialogOpen, isDisablingPropagation])
101-
10276
// If we stack multiple modals and drawers on mobile then we shouldn't trap focus
10377
useLayoutEffect(() => {
10478
if (!isMobile || isLargerThanMd) return
@@ -118,20 +92,11 @@ const DialogWindow: React.FC<DialogProps> = ({
11892
repositionInputs={isFullScreen ? true : false}
11993
open={isDialogOpen}
12094
onClose={onClose}
121-
activeSnapPoint={isDisablingPropagation ? snapPoint : undefined}
122-
modal={false}
95+
activeSnapPoint={snapPoint}
96+
modal
12397
>
12498
<Drawer.Portal>
125-
{!isDisablingPropagation ? (
126-
<Box
127-
bg='rgba(0, 0, 0, 0.8)'
128-
position='fixed'
129-
inset={0}
130-
zIndex='overlay'
131-
onClick={onClose}
132-
/>
133-
) : null}
134-
{isDisablingPropagation ? <CustomDrawerOverlay onClick={onClose} /> : null}
99+
<CustomDrawerOverlay onClick={onClose} />
135100
<CustomDrawerContent style={contentStyle}>{children}</CustomDrawerContent>
136101
</Drawer.Portal>
137102
</Drawer.Root>

src/components/Modals/ManageAccounts/ManageAccountsModal.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ export const ManageAccountsModal = ({ onBack }: ManageAccountsModalProps) => {
121121

122122
return (
123123
<>
124-
<Dialog
125-
isOpen={isOpen}
126-
onClose={close}
127-
isDisablingPropagation={false}
128-
isFullScreen={false}
129-
height='auto'
130-
>
124+
<Dialog isOpen={isOpen} onClose={close} isFullScreen={false} height='auto'>
131125
<ManageAccountsDrawer
132126
isOpen={isDrawerOpen}
133127
onClose={handleDrawerClose}

src/components/MultiHopTrade/components/TradeInput/components/HighlightedTokensCategoryDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const HighlightedTokensCategoryDialog = ({
5555
handleCategoryChange,
5656
}: HighlightedTokensCategoryDialogProps) => {
5757
return (
58-
<Dialog isOpen={isOpen} onClose={onClose} height='auto' isDisablingPropagation={false}>
58+
<Dialog isOpen={isOpen} onClose={onClose} height='auto'>
5959
<Box
6060
py={4}
6161
pb='calc(env(safe-area-inset-bottom) + var(--safe-area-inset-bottom) + var(--chakra-space-4))'

src/components/MultiHopTrade/components/TradeInput/components/HighlightedTokensFiltersDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const HighlightedTokensFiltersDialog = ({
9797
])
9898

9999
return (
100-
<Dialog isOpen={isOpen} onClose={onClose} height='auto' isDisablingPropagation={false}>
100+
<Dialog isOpen={isOpen} onClose={onClose} height='auto'>
101101
<Box height='5px' width='36px' borderRadius='full' bg='gray.500' mb={4} mx='auto' my={4} />
102102
<Box
103103
pb='calc(env(safe-area-inset-bottom) + var(--safe-area-inset-bottom) + var(--chakra-space-4))'

0 commit comments

Comments
 (0)