mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
fix: cancel popover wheel frames (#3460)
This commit is contained in:
@@ -28,6 +28,18 @@ function PopoverContent({
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Content> & {
|
||||
portalContainer?: HTMLElement | null
|
||||
}) {
|
||||
const wheelFrameIdsRef = React.useRef<Set<number>>(new Set())
|
||||
|
||||
React.useEffect(
|
||||
() => () => {
|
||||
for (const frameId of wheelFrameIdsRef.current) {
|
||||
cancelAnimationFrame(frameId)
|
||||
}
|
||||
wheelFrameIdsRef.current.clear()
|
||||
},
|
||||
[]
|
||||
)
|
||||
|
||||
const handleWheel = React.useCallback(
|
||||
(event: React.WheelEvent<HTMLDivElement>) => {
|
||||
onWheel?.(event)
|
||||
@@ -55,11 +67,13 @@ function PopoverContent({
|
||||
if (nextScrollTop !== el.scrollTop) {
|
||||
const previousScrollTop = el.scrollTop
|
||||
event.stopPropagation()
|
||||
requestAnimationFrame(() => {
|
||||
const frameId = requestAnimationFrame(() => {
|
||||
wheelFrameIdsRef.current.delete(frameId)
|
||||
if (el.scrollTop === previousScrollTop) {
|
||||
el.scrollTop = nextScrollTop
|
||||
}
|
||||
})
|
||||
wheelFrameIdsRef.current.add(frameId)
|
||||
}
|
||||
},
|
||||
[onWheel]
|
||||
|
||||
Reference in New Issue
Block a user