Skip to content

Commit 025919e

Browse files
committed
Fix modal position when resizing browser window
1 parent 0715834 commit 025919e

File tree

1 file changed

+21
-0
lines changed
  • src/theme/CodeBlock/VideoPlayer/VideoModal

1 file changed

+21
-0
lines changed

src/theme/CodeBlock/VideoPlayer/VideoModal/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {
22
useCallback,
33
useEffect,
44
useRef,
5+
useLayoutEffect,
56
useState,
67
} from 'react'
78
import Draggable, {
@@ -56,6 +57,26 @@ function VideoModal({
5657
onTimeChange,
5758
])
5859

60+
useLayoutEffect(() => {
61+
if (!draggableContainerRef.current) return
62+
63+
const observer = new IntersectionObserver(([entry]) => {
64+
if (!entry) return
65+
if (!entry.isIntersecting) {
66+
changePosition({ x: 0, y: 0 })
67+
}
68+
})
69+
70+
observer.observe(draggableContainerRef.current)
71+
return () => {
72+
observer.disconnect()
73+
}
74+
}, [
75+
position,
76+
changePosition,
77+
draggableContainerRef,
78+
])
79+
5980
const stopDragging = useCallback<DraggableEventHandler>((_, data) => {
6081
setIsDragged(false)
6182

0 commit comments

Comments
 (0)