Skip to content

Commit 8e37913

Browse files
committed
fix: wrapped element x,y detection
Signed-off-by: Innei <[email protected]>
1 parent 288faf2 commit 8e37913

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/providers/shared/WrappedElementProvider.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,27 @@ export const WrappedElementProvider: Component<WrappedElementProviderProps> = ({
7070
const ArticleElementResizeObserver = () => {
7171
const setSize = useSetWrappedElementSize()
7272
const setPos = useSetElementPosition()
73-
const $article = useWrappedElement()
73+
const $element = useWrappedElement()
7474
useIsomorphicLayoutEffect(() => {
75-
if (!$article) return
76-
const { height, width, x, y } = $article.getBoundingClientRect()
75+
if (!$element) return
76+
const { height, width, x, y } = $element.getBoundingClientRect()
7777
setSize({ h: height, w: width })
7878
setPos({ x, y })
7979

8080
const observer = new ResizeObserver((entries) => {
8181
const entry = entries[0]
82-
const { height, width, x, y } = entry.contentRect
82+
const { height, width } = entry.contentRect
83+
const { x, y } = entry.target.getBoundingClientRect()
84+
8385
setSize({ h: height, w: width })
8486
setPos({ x, y })
8587
})
86-
observer.observe($article)
88+
observer.observe($element)
8789
return () => {
88-
observer.unobserve($article)
90+
observer.unobserve($element)
8991
observer.disconnect()
9092
}
91-
}, [$article])
93+
}, [$element])
9294

9395
return null
9496
}

0 commit comments

Comments
 (0)