Skip to content

Commit

Permalink
Fix modal position when resizing browser window
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Jul 28, 2022
1 parent 0715834 commit 025919e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/theme/CodeBlock/VideoPlayer/VideoModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {
useCallback,
useEffect,
useRef,
useLayoutEffect,
useState,
} from 'react'
import Draggable, {
Expand Down Expand Up @@ -56,6 +57,26 @@ function VideoModal({
onTimeChange,
])

useLayoutEffect(() => {
if (!draggableContainerRef.current) return

const observer = new IntersectionObserver(([entry]) => {
if (!entry) return
if (!entry.isIntersecting) {
changePosition({ x: 0, y: 0 })
}
})

observer.observe(draggableContainerRef.current)
return () => {
observer.disconnect()
}
}, [
position,
changePosition,
draggableContainerRef,
])

const stopDragging = useCallback<DraggableEventHandler>((_, data) => {
setIsDragged(false)

Expand Down

0 comments on commit 025919e

Please sign in to comment.