Skip to content

Commit

Permalink
chore: fix issue where scroll would get reset in popovers [skip e2e]
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Aug 16, 2023
1 parent a3d1f7d commit 6a84f25
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useDocumentRect } from '@/Hooks/useDocumentRect'
import { useAutoElementRect } from '@/Hooks/useElementRect'
import { classNames } from '@standardnotes/utils'
import { CSSProperties, useCallback, useLayoutEffect, useState } from 'react'
import { CSSProperties, useCallback, useLayoutEffect, useRef, useState } from 'react'
import Portal from '../Portal/Portal'
import { PopoverCSSProperties, getPositionedPopoverStyles } from './GetPositionedPopoverStyles'
import { PopoverContentProps } from './Types'
Expand Down Expand Up @@ -85,9 +85,11 @@ const PositionedPopoverContent = ({

useDisableBodyScrollOnMobile()

const canCorrectInitialScroll = useRef(true)
const correctInitialScrollForOverflowedContent = useCallback((element: HTMLElement | null) => {
if (element && element.scrollTop > 0) {
if (element && element.scrollTop > 0 && canCorrectInitialScroll.current) {
element.scrollTop = 0
canCorrectInitialScroll.current = false
}
}, [])

Expand Down Expand Up @@ -145,6 +147,9 @@ const PositionedPopoverContent = ({
className,
)}
ref={mergeRefs([correctInitialScrollForOverflowedContent, setAnimationElement])}
onScroll={() => {
canCorrectInitialScroll.current = false
}}
>
{children}
</div>
Expand Down

0 comments on commit 6a84f25

Please sign in to comment.