Skip to content

Commit 64fb3a5

Browse files
authored
fix: Position drag UAPs correctly on same-origin iframes sharing a React tree (#3502)
1 parent 6a94647 commit 64fb3a5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/internal/components/drag-handle-wrapper/portal-overlay.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import React, { useEffect, useRef } from 'react';
3+
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
44

55
import {
66
getIsRtl,
@@ -21,6 +21,16 @@ export default function PortalOverlay({
2121
children: React.ReactNode;
2222
}) {
2323
const ref = useRef<HTMLSpanElement | null>(null);
24+
const [container, setContainer] = useState<HTMLDivElement | null>(null);
25+
26+
useLayoutEffect(() => {
27+
if (track.current) {
28+
const newContainer = track.current.ownerDocument.createElement('div');
29+
track.current.ownerDocument.body.appendChild(newContainer);
30+
setContainer(newContainer);
31+
return () => newContainer.remove();
32+
}
33+
}, [track]);
2434

2535
useEffect(() => {
2636
if (track.current === null || isDisabled) {
@@ -68,12 +78,8 @@ export default function PortalOverlay({
6878
};
6979
}, [isDisabled, track]);
7080

71-
if (track === null) {
72-
return null;
73-
}
74-
7581
return (
76-
<Portal>
82+
<Portal container={container}>
7783
<span ref={ref} className={styles['portal-overlay']}>
7884
<span className={styles['portal-overlay-contents']}>{children}</span>
7985
</span>

0 commit comments

Comments
 (0)