fix: avoid scrollTo on pageload (#7323)

This commit is contained in:
Zach Pomerantz 2023-09-18 13:09:01 -07:00 committed by GitHub
parent c528c6169e
commit ad9879b4f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@ import { BrowserEvent, InterfaceEventName } from '@uniswap/analytics-events'
import { TraceEvent } from 'analytics'
import { ScrollBarStyles } from 'components/Common'
import useDisableScrolling from 'hooks/useDisableScrolling'
import usePrevious from 'hooks/usePrevious'
import { useWindowSize } from 'hooks/useWindowSize'
import { atom } from 'jotai'
import { useAtomValue, useUpdateAtom } from 'jotai/utils'
@ -166,12 +167,13 @@ const CloseDrawer = styled.div`
function AccountDrawer() {
const [walletDrawerOpen, toggleWalletDrawer] = useAccountDrawer()
const wasWalletDrawerOpen = usePrevious(walletDrawerOpen)
const scrollRef = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!walletDrawerOpen) {
if (wasWalletDrawerOpen && !walletDrawerOpen) {
scrollRef.current?.scrollTo({ top: 0, behavior: 'smooth' })
}
}, [walletDrawerOpen])
}, [walletDrawerOpen, wasWalletDrawerOpen])
// close on escape keypress
useEffect(() => {