fix: avoid scrollTo on pageload (#7323)
This commit is contained in:
parent
c528c6169e
commit
ad9879b4f9
@ -2,6 +2,7 @@ import { BrowserEvent, InterfaceEventName } from '@uniswap/analytics-events'
|
|||||||
import { TraceEvent } from 'analytics'
|
import { TraceEvent } from 'analytics'
|
||||||
import { ScrollBarStyles } from 'components/Common'
|
import { ScrollBarStyles } from 'components/Common'
|
||||||
import useDisableScrolling from 'hooks/useDisableScrolling'
|
import useDisableScrolling from 'hooks/useDisableScrolling'
|
||||||
|
import usePrevious from 'hooks/usePrevious'
|
||||||
import { useWindowSize } from 'hooks/useWindowSize'
|
import { useWindowSize } from 'hooks/useWindowSize'
|
||||||
import { atom } from 'jotai'
|
import { atom } from 'jotai'
|
||||||
import { useAtomValue, useUpdateAtom } from 'jotai/utils'
|
import { useAtomValue, useUpdateAtom } from 'jotai/utils'
|
||||||
@ -166,12 +167,13 @@ const CloseDrawer = styled.div`
|
|||||||
|
|
||||||
function AccountDrawer() {
|
function AccountDrawer() {
|
||||||
const [walletDrawerOpen, toggleWalletDrawer] = useAccountDrawer()
|
const [walletDrawerOpen, toggleWalletDrawer] = useAccountDrawer()
|
||||||
|
const wasWalletDrawerOpen = usePrevious(walletDrawerOpen)
|
||||||
const scrollRef = useRef<HTMLDivElement>(null)
|
const scrollRef = useRef<HTMLDivElement>(null)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!walletDrawerOpen) {
|
if (wasWalletDrawerOpen && !walletDrawerOpen) {
|
||||||
scrollRef.current?.scrollTo({ top: 0, behavior: 'smooth' })
|
scrollRef.current?.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
}
|
}
|
||||||
}, [walletDrawerOpen])
|
}, [walletDrawerOpen, wasWalletDrawerOpen])
|
||||||
|
|
||||||
// close on escape keypress
|
// close on escape keypress
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user