Skip to content

Commit 3f19120

Browse files
Attach handlePointerUp to ownerDocument body
1 parent 96a4c5b commit 3f19120

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

packages/react-resizable-panels/src/PanelResizeHandle.test.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,37 @@ describe("PanelResizeHandle", () => {
258258
});
259259
});
260260

261+
262+
describe("event handlers when rendered in a separate document", () => {
263+
let separateWindowDocument: Document;
264+
beforeEach(() => {
265+
// @ts-expect-error
266+
global.IS_REACT_ACT_ENVIRONMENT = true;
267+
268+
separateWindowDocument = document.implementation.createHTMLDocument();
269+
container = separateWindowDocument.createElement("div");
270+
separateWindowDocument.body.appendChild(container);
271+
jest.spyOn(separateWindowDocument.body,"addEventListener");
272+
jest.spyOn(document.body,"addEventListener");
273+
expectedWarnings = [];
274+
root = createRoot(container);
275+
});
276+
277+
it("should add the pointerup event to the separate document NOT the main document", () => {
278+
const { leftElement } = setupMockedGroup();
279+
280+
act(() => {
281+
dispatchPointerEvent("pointerdown", leftElement);
282+
dispatchPointerEvent("pointerup", leftElement);
283+
});
284+
285+
expect(separateWindowDocument.body.addEventListener).toHaveBeenCalledWith("pointerup", expect.anything(), expect.anything());
286+
expect(document.body.addEventListener).not.toHaveBeenCalled();
287+
288+
});
289+
});
290+
291+
261292
describe("data attributes", () => {
262293
it("should initialize with the correct props based attributes", () => {
263294
const { leftElement, rightElement } = setupMockedGroup();

packages/react-resizable-panels/src/PanelResizeHandleRegistry.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ function updateListeners() {
327327
}
328328
});
329329
}
330-
331-
window.addEventListener("pointerup", handlePointerUp, options);
332-
window.addEventListener("pointercancel", handlePointerUp, options);
330+
ownerDocumentCounts.forEach((count, ownerDocument) => {
331+
const { body } = ownerDocument;
332+
body.addEventListener("pointerup", handlePointerUp, options);
333+
body.addEventListener("pointercancel", handlePointerUp, options);
334+
});
333335
} else {
334336
ownerDocumentCounts.forEach((count, ownerDocument) => {
335337
const { body } = ownerDocument;

0 commit comments

Comments
 (0)